BB___ON_ERROR

=ON ERROR= toc

Description
> ON ERROR goto [branchLabel] provides a way to handle the event if your program encounters an error. Err and Err$ hold the error code number and the description. See Err.

Syntax

 * 1)  - (cannot be a sub)

Hints
> Here is a link to QBasic error codes. Several of these are supported by JB. Some do not apply. Other error codes have been added. >

> Here is a short list of common error codes:

3	-	RETURN without GOSUB 4	-	Read past end of data 8	-	Branch label not found 9	-	Subscript out of range 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

> Some errors do not have a numeric value and the value of Err will be zero.

> Some errors could not be trapped (for example, pressing CtrlBeak)

> In JB, error handler is local to the procedure.

> If an error occurs in a user function or subroutine, Just BASIC will exit the current function or subroutine and continue to exit functions and subroutines until it finds ON ERROR handler.

> In JB, there is no support for RESUME.

> In JB, there is no way to turn Error handling off. (so having it local in a sub/function might be wise).

Example
An example trying to open a file that does not exist. The following will be printed to the mainwin: > code format="lb" Error string is "OS Error: The system cannot find the file specified." Error number is 53 code

code format="lb" on error goto [errorHandler]

open "nofilename.txt" for input as #f close #f

end

[errorHandler] print "Error string is " + chr$(34) + Err$ + chr$(34) print "Error number is ";Err end code

Useful Functions
Function that catches error on > (because there are some BMP JB could not open)

code format="lb" function loadBmpErrChk(bmpName$, fName$) 'returns 1 on success, 0 on failure on error goto [errHandler] loadbmp bmpName$, fName$ loadBmpErrChk = 1 exit function [errHandler] loadBmpErrChk = 0 end function code