Catch

Specifies the code to execute if an exception is raised during execution of a try statement.

Catch OutputVar
    Statement
Catch OutputVar
{
    Statements
}

Parameters

OutputVar

Type: Variable

(Optional) The variable in which to store the thrown value or exception object. This cannot be a dynamic variable.

Statement(s)

The functions or expressions to execute if an exception is raised.

Remarks

OutputVar may optionally be enclosed in parentheses, in which case the space or tab after Catch is optional.

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 One True Brace (OTB) style may optionally be used. For example:

try {
    ...
} catch e {
    ...
}

Runtime Errors

A try-catch statement can also be used to handle runtime errors raised during evaluation of the script or by a built-in function. If a runtime error or exception is not handled, an error message is displayed and the current thread exits. Loadtime errors cannot be handled, since they occur before the try statement is executed.

The value that is stored in OutputVar (if present) is an exception object.

Related

Try, Throw, Finally, Blocks, OnError

Examples

See Try.