Commands: try/catch

Syntax

try { <level> } "{"
   <commands>
"}"

catch <exception> "{"
   <commands>
"}"

Description

try:   Execute a command block which detects exceptions.
catch: Catch an exception detected within the corresponding try command block.

Parameters

Switches

none

Notes

Two types of exception can be thrown within a try block: system exceptions and user exceptions:

System exceptions are thrown as a result of language or data errors detected by the system. This is done automatically without any user action.

User exceptions are thrown by a throw command, typically executed as a result of an error detected by application macro code.

Exceptions detected within a try command block may be thrown in the current command frame or in sub-frames, e.g. called functions or procedures.

Examples

Code to catch a maths warning:

try 10 {
   numeric x = sqrt(-10);# A mathematical anomaly
# We will never get here
}
catch exc {
# Just list the error details
    list exc
}

See Also

Commands:

exception, throw

Functions:

error_exception, interrupt_exception, warning_exception

Identifiers:

throw_level (numeric)

Structures:

exception