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 executes when an error occurs.
catch_parameter
Optional declaration of an object variable. The type of the object given to Raise selects which block (Catch) executes.
If not given, then Catch will execute for all errors. This can be done only as the last block of Catch.
catch_statements
Optional statements that execute when an error occurs.
finally_statements
Optional statements that always execute. If an error occurred, then the statements execute 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