# Catch [v1.1.04+]

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

    Catch [, OutputVar]
        Statement

    Catch [, OutputVar]
    {
        Statements
    }

### Parameters

OutputVar | (Optional) The name of the variable in which to store the value of the exception.
Statement(s) | The commands or expressions to execute if an exception is raised.

### Remarks

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. There are two kinds of runtime errors: those which normally set ErrorLevel, and those which normally cause the current thread to exit after displaying an error message. Loadtime errors cannot be handled, since they occur before the try statement is executed. For backward-compatibility (and in some cases convenience), runtime errors only throw exceptions while a try block is executing. Most commands support the use of try-catch; however, ErrorLevel is still set to 0 if the command succeeds.

The value that is stored in OutputVar (if present) is an object that contains the following fields:

What: The name of the command or function which was executing or about to execute when the error occurred. File: The full path of the script file which contains the line at which the error occurred. Line: The line number at which the error occurred. Message: An error message or ErrorLevel value. Extra: Additional information about the error, if available.

Note: These details should be used only for debugging purposes as they may change in a future version.

### Related

Try, Throw, Blocks

### Examples

See Try.