THROW

Statement

Syntax

Raises an error that the nearest enclosing CATCH receives. Without a CATCH, the program stops at that line.

THROW <value>

Parts

<value>A string, a number, or a record with a message field and an optional code field. A string or number becomes the message. A record gives its message and code.

Good to know

  • THROW without a value is a compile error: "THROW requires a value".
  • The error leaves every function on the way until a CATCH takes it, so a function can throw and its caller can catch.
  • The name of a thrown error is always Error. The code is "" unless a record gave one.
  • Do not THROW the error you caught: the name becomes Error and the command is lost. Use RETHROW to pass it on unchanged.
  • A THROW inside a task does not stop the program. It marks the task as failed, and the error comes back at AWAITTASK or TaskResult().

Example

FUNCTION Reload(ammo)  IF ammo = 0 THEN THROW "no ammo left"  Console("reloaded")ENDFUNCTIONTRY  Reload(0)CATCH failure  Console(failure.name + ": " + failure.message)   ' Error: no ammo leftENDTRY
In the manual : Errors