Liberty BASIC Help Online

ON ERROR GOTO [branchLabel]
Liberty BASIC 4 adds support for ON ERROR GOTO. 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.
If an error occurs in a user function or subroutine, Liberty BASIC will exit the current function or subroutine and continue to exit functions and subroutines until it finds ON ERROR handler.
If an error is encountered, a program can attempt to resume execution with the RESUME statement.
Here is a short list of error codes:
4Read past end of data
8Branch label not found
9Subscript out of range
11Division by zero
53OS Error: The system cannot find the file specified.
58OS Error: Cannot create a file when that file already exists.
55Error opening file
52Bad file handle
62Input past end of file
on error goto [errorHandler]
open "sillyfilename.txt" for input as #f
close #f
print "Error string is " + chr$(34) + Err$ + chr$(34)
print "Error number is ";Err
The program above will print the following in the mainwin:
Error string is "OS Error: The system cannot find the file specified."
Error number is 53
'demonstrate the use of RESUME
    on error goto [whoops]
    global divideBy
    call causeWhoops
    print "whoops!"
    print "Error "; Err$; " "; " code "; Err
    divideBy = 2
sub causeWhoops
    print 10 / divideBy
end sub

Copyright (C) 2003 Shoptalk Systems
Liberty BASIC -