On Error
Error handling statement to set the current error handler
Syntax
`
On [Local] Error Goto label
`
Usage
`
On [Local] Error Goto label
`
Parameters
`label`
label to jump to when error occurs
Description
`On Error` triggers a jump to an error handler when an error occurs.
If `Local` is not used the handler must be in the main part of the module. Using `Local` allows to have the error handler inside the `Sub`/`Function` where the `On Error` is located.
`On Error GOTO 0` deactivates the current error handler.
The use of QB-like error handling requires compilation with switch -e, -ex or -exx activated.
See Runtime Error Codes for a listing of runtime error numbers and their associated meaning.
Example
`
'' Compile with QB (-lang qb) dialect
'$lang: "qb"
On Error Goto errorhandler
Error 24 '' simulate an error
Print "this message will not be seen"
errorhandler:
Print "Error #"; Err; "!"
End
`
Dialect Differences

- ON ERROR is supported in the -lang qb dialect only. In the -lang fb dialect, statements can be used in function form to return an error code

`
'' Compile with FB default (-lang fb) dialect
If Open( "text" For Input As #1 ) <> 0 Then
Print "Unable to open file"
End If
`
Differences from QB

- QB has no LOCAL clause and requires the label to be in the main part of the module.

See also

- `Error`
- `Local`
- `Err`
- Runtime Error Codes