throw function

Syntax

throw expression

Description

Use the throw statement to throw an exception. This can be used to create your own exceptions, instead of using ones generated by the system.

Parameters

Parameter Description

expression

Specify the exception object that you want to throw. This can either be an already defined and created exception object, or one that you create with the Throw statement.

Returns

None.

Example

Local Exception &ex;

Function t1(&i As integer) Returns number
   Local number &res = &i / 0;
End-Function;

Function t2
   throw CreateException(2, 160, "'%1' doesn't support property or method '%2'",⇒
 "SomeClass", "SomeMethod");
End-Function;

try
   /* This will cause a divide by 0 leading to an exception             */
   /* This code will never be caught since t1(2) will resume execution  */
   /* in the catch block below. It is here to show how an exception can */
   /* be thrown directly bythe PeopleCode itself.                       */
   t2();
   Local number &res = t1(2);
catch Exception &caught
   MessageBox(0, "", 0, 0, "Caught exception: " | &caught.ToString());
end-try;