Copyright 2008 Shoptalk Systems
ON ERROR GOTO [branchLabel]
Define a global error handler at [branchLabel]. The routine must not be defined inside a SUB or FUNCTION. If an error occurs in a user function or subroutine, Run BASIC will exit the current function or subroutine and continue to exit functions and subroutines until it finds ON ERROR handler. Failing that, the program will stop with an error message.
Several of the QBasic error codes are supported, but some are not relevant, and there are some new ones. When an error occurs, the special variables Err and Err$ hold numeric and string values describing what sort of error happened. Some kinds of errors do not have a numeric value, in which case Err will be zero.
Here is a short list of error codes:
3 RETURN without GOSUB
4 Read past end of data
8 Branch label not found
9 Index out of bounds (For arrays)
11 Division by zero
53 OS Error: The system cannot find the file specified.
58 OS Error: Cannot create a file when that file already exists.
55 Error opening file
52 Bad file handle
62 Input past end of file
on error goto [errorHandler]
open "sillyfilename.txt" for input as #f
print "Error string is " + chr$(34) + Err$ + chr$(34)
print "Error number is ";Err
Error string is "File not found: c:\rbp\sillyfilename.txt"
Error number is 53
Note: The RESUME statement is not supported.