Futurebasic/Language/Reference/on error fn


Statements edit

(+) Appearance (+) Standard Console

Syntax edit

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

Revised edit

June, 2001 (Release 5)

Description edit

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.


<code><b>LOCAL FN</b> handleFileError<br>
<b>ÊÊPRINT</b> "Sorry. Something has gone wrong."<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>


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.