Try…Catch…Finally Statement

Lets you catch many errors that can occur in a given block of code.

Syntax

Try
    [ try_statements ]
[ Catch [ catch_parameter ]
    [ catch_statements ] ]
…
[ Finally
    [ finally_statements ] ]
End [ Try ]

Parts

try_statements
Optional statements in which errors can occur.
Catch
Optional start of a block of statements that you can use again and again. It runs when an error occurs.
catch_parameter
Optional declaration of an object variable. The type of the object given to Raise selects which block (Catch) runs.
If not given, Catch will run for all errors. This can be done only as the last block in a sequence of such blocks.
catch_statements
Optional statements that run when an error occurs.
finally_statements
Optional statements that always run. If an error occurred, the statements run after Catch is done.
End
Completes the statement. You can also use End Try.
You can change this part of the syntax. See @Option Directive for more information.

Instructions

TODO

Examples

Try
    ' Cause a division by zero.
    x = a / 0
Catch #ex As Exception
    ' Do something about the error.
End Try

See also