Futurebasic/Language/Reference/on error fn

ON ERROR FN / GOSUBEdit

StatementsEdit

(+) Appearance (+) Standard Console

SyntaxEdit

<code><b>ON ERROR</b> {<b>FN</b> userFunction|<b>GOSUB</b>{<i>lineNumber</i>|<i>"stmtLabel"</i>}}</code>

RevisedEdit

June, 2001 (Release 5)

DescriptionEdit

This statement designates and enables the routine that FB 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:

<code><b>LOCAL FN</b> handleFileError<br>
<b>ÊÊPRINT</b> "Sorry. Something has gone wrong."<br>
<b>ÊÊSTOP</b><br>
<b>END FN</b></code>

<code><b>ON ERROR FN</b> handleFileError<br>
<b>OPEN</b> "I",#1,"this file does not exist"</code>

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 AlsoEdit

ON ERROR END; ON ERROR RETURN; ERROR function; SYSERROR function