TRY ... CATCH ... END TRY
TRY
THROW expression
{ statement }
[ CATCH expr
{ statement }
REDO ]
[ CATCH | ELSE
{ statement }
REDO ]
[ FINALLY
{ statement }
REDO ]
END TRY
Try catches errors thrown either by wxBasic when an error occurs, or by the application via the Throw statement.
If an error occurs, code jumps to the first Catch statement. If no Catch statement handles the exception, it jumps to the next Try block. A Catch without a test expression matches any thrown error.
To execute the Try block again, call Redo.
The Finally clause is always executed, even if no error occurred. For example:
' attempt to open a file
TRY
OPEN "myfile.txt" FOR INPUT AS #1
PRINT "This is written to the file"
CATCH
PRINT "Error printing to the file"
FINALLY
CLOSE #1
END TRY