Type in the words(s) to search for:

    Mark results
      Userbooster Help

      try, catch, finally, throw Statements

      The try...catch...finally statement implements exception handling.

      try
          tryStatement
      catch ( exception )
          catchStatement
      finally
          finallyStatement 

      Arguments

      tryStatement

      Compound statement where an error may occur.

      exception

      Name of the variable that keeps the value of the thrown error or object.

      catchStatement

      Compound statement to handle an error occurred in the associated tryStatement.

      finallyStatement

      Compound statement that is unconditionally executed after all other error handling blocks are finished. The argument is optional.

      Remarks

      The try...catch...finally statement provides a way to handle some or all errors that may occur in a block of code and allow the code to continues running.

      Either catchStatement or finallyStatement can be absent but not both.

      The throw statement throws an error that can be handled by a try...catch...finally statement.

      
      

      The required exception argument can be any expression.

      Example

      function main()
      {
          try
          {
              raise_exception();
          }
          catch( e )
          {
              cout << "caught:\n" + e;
          }
      }
      
      function raise_exception()
      {
          try
          {
              throw
                  "WHERE WE ARE:"
                  + "line " + __LINE__
                  + " of \"" + __FILE__ + "\"\n"
                  + "date is \"" + __DATE__ + "\"\n"
                  + "time is \"" + __TIME__ + "\"\n"
                  + "time zone is \"" + __TZ__ + "\"\n"
                  ;
          }
          finally
          {
              cout << "exception raised!\n\n";
          }
      }