FutureBasic Logo

<<    Index    >> FutureBasic 5

on error fn / gosub   statement



Syntax:
on error {fn userFunction|gosub{lineNumber|"stmtLabel"}}

Description:
This statement designates and enables the routine that FutureBasic will call when certain kinds of errors occur. There may only be one on error vector. If you use a second call to on error fn, the new routine replaces the old version in subsequent calls. However you can deactivate or reactivate error trapping as often as you need. Using the on error end/on error return statements you can switch between the default behavior and your error handler.

Example:
local fn handleFileError
  print "Sorry. Something has gone wrong."
  stop
end fn

on error fn handleFileError
open "I",#1,"this file does not exist"


Note:
If you use the on error fn userFunction syntax, then userFunction must refer to a function which was defined or prototyped at an earlier location in the source code. Your error handling function should not take any parameters, nor return a result.

See Also:
on error end; on error return; error function