Specifies one or more statements to execute if a value or error is thrown during execution of a Try statement.
Catch ErrorClass as OutputVar { Statements }
Type: Class
The class of value that should be caught, such as Error
, TimeoutError
or MyCustomError
. This can also be a comma-delimited list of classes. Classes must be specified by their exact full name and not an arbitrary expression, as the Prototype of each class is resolved at load time. Any built-in or user-defined class can be used, even if it does not derive from Error.
If no classes are specified, the default is Error
.
To catch anything at all, use catch Any
.
A load-time error is displayed if an invalid class name is used, or if a class is inaccessible due to the presence of a local variable with the same name.
Type: Variable
The output variable in which to store the thrown value, which is typically an Error object. This cannot be a dynamic variable.
If omitted, the thrown value cannot be accessed directly, but can still be re-thrown by using Throw with no parameter.
The statements to execute if a value or error is thrown.
Braces are generally not required if only a single statement is used. For details, see {...} (block).
Multiple Catch statements can be used one after the other, with each one specifying a different class (or multiple classes). If the value is not an instance of any of the listed classes, it is not caught by this Try-Catch, but might be caught by one further up the call stack.
Every use of Catch must belong to (be associated with) a Try statement above it. A Catch always belongs to the nearest unclaimed Try statement above it unless a block is used to change that behavior.
The parameter list may optionally be enclosed in parentheses, in which case the space or tab after catch
is optional.
Catch may optionally be followed by Else, which is executed if no exception was thrown within the associated Try block.
The One True Brace (OTB) style may optionally be used. For example:
try { ... } catch Error { ... }
Load-time errors cannot be caught, since they occur before the try statement is executed.
Try, Throw, Error Object, Else, Finally, Blocks, OnError
See Try.