Throw

Signals the occurrence of an error. This signal can be caught by a Try-Catch statement.

Throw Value

Parameters

Value

A value to throw; typically an Error object. For example:

throw ValueError("Parameter #1 invalid", -1, theBadParam)

Values of all kinds can be thrown, but if Catch is used without specifying a class (or Try is used without Catch or Finally), it will only catch instances of the Error class.

While execution is within a Catch, Value can be omitted to re-throw the caught value (avoiding the need to specify an output variable just for that purpose). This is supported even within a nested Try-Finally, but not within a nested Try-Catch. The line with throw does not need to be physically contained by the Catch statement's body; it can be used by a called function.

Remarks

The space or tab after throw is optional if the expression is enclosed in parentheses, as in throw(Error()).

A thrown value or runtime error can be caught by Try-Catch. In such cases, execution is transferred into the catch statement or to the next statement after the try. If a thrown value is not caught, the following occurs:

Error Object, Try, Catch, Finally, OnError

Examples

See Try.