Exceptions

BlitzMax provides a mechanism for handling runtime errors known as exception handling.

An exception is actually just an object. You can throw and catch exceptions using the Throw command and a Try/Catch block. Here is a simple example:
Function ExTest()
	Throw "Bingo!"
End Function

Try
	ExTest()
Catch ex:Object
	Print ex.ToString()
End Try
Throwing an exception causes the program to jump to nearest Catch block. You can provide multiple catch blocks for catching exceptions of different types. If there is no Catch block, then the exception is sent to the debugger which usually has the effect of halting the program with an appropriate message.

Exception objects should implement the ToString method of Object to provide a textual description of the exception.

BlitzMax has several built-in exception types. These are:

ExceptionCause
TNullObjectExceptionThrown when a program attempts to access a null object
TNullMethodExceptionThrown when a program attempts to call an abstract method
TNullFunctionExceptionThrown when a program attempts to call a null function
TArrayBoundsExceptionThrown when a program attempts to access an array element outside of an array's bounds
TRuntimeExceptionThrown by the RuntimeError or Assert commands

All of these types extend TBlitzException.