catch

In a try...endtry block, introduces the code to catch and handle exceptions.

try
    <ProcScript that may throw an exception>
{catch} {ErrorNumber1 {,ErrorNumberN}}
    <Procscript that handles the error >
endtry

Parameters

Parameters
Parameter Data Type Description
ErrorNumbers Numeric A comma-separated list of error numbers that the catch statement will catch.

If omitted, the catch block catches any exception.

Return Values

None.

Use

Allowed in all component types.

Description

For each try declaration, it is possible to have multiple catch statements to test for specific errors. The endtry command must come after the last catch statement.

Each catch block catches only the exceptions that are specified in its comma-separated list of arguments. If there are multiple catch blocks, they are processed in order.

If you specify a catch statement without arguments, it must be the last catch block because it catches any exception.

Within a catch block, the error information is available in $procerror and $procerrorcontext. For example, the following code puts a message in the message frame if an exception is thrown when calling the Do_It entry:

trigger detail
  try
    call Do_It()
  catch
    putmess "An error occurred: %%($procerror): %%($procerrorcontext)" 
  endtry
end

This error information is not available outside the specific catch block.

A catch block can also contain a rethrow statement. This allows you to rethrow an exception that was caught in the catch block.

Note: A catch block can also throw an exception. In this case, the exception will bubble up to a higher level.

The goto statement and ProcScript label are not allowed inside a catch block, and will result in a compilation error.

For more information, see Exception Handling and try.

Related Topics