REM Errorhandler
'Include file of errors which can be trapped
'Requires Intuits.SUB
'Program must have a label for recovery called RECOVER:
'Also includes a break handler for ^C traps which requires label QUIT:
'
error_handler:
	err_no%=ERR
	err_line%=ERL
	SELECT CASE err_no%
		CASE 4
			pgm_err$="Out of Data"
			GOTO exit_handler
		CASE 6
			pgm_err$="Overflow"
			GOTO exit_handler
		CASE 7
			LIBRARY CLOSE
			CLOSE
			END
		CASE 11
			pgm_err$="Division by Zero"
			GOTO exit_handler
		CASE 49
			pgm_err$="Volume Not Found"
			GOTO exit_handler
		CASE 52
			pgm_err$="Bad File Number"
			GOTO exit_handler
		CASE 53
			pgm_err$="File Not Found"
			GOTO exit_handler
		CASE 54
			pgm_err$="Bad File Mode"
			GOTO exit_handler
		CASE 55
			pgm_err$="File Already Open"
			GOTO exit_handler
		CASE 57
			pgm_err$="Device I/O Error"
			GOTO exit_handler
		CASE 61
			pgm_err$="Disk Full"
			GOTO exit_handler
		CASE 64
			pgm_err$="Bad File Name"
			GOTO exit_handler
		CASE 67
			pgm_err$="Directory Full"
			GOTO exit_handler
		CASE 70
			pgm_err$="Disk Write Protected"
			GOTO exit_handler
		CASE 75
			pgm_err$="Path/File Access Error"
			GOTO exit_handler
		CASE 76
			pgm_err$="Path Not Found"
			GOTO exit_handler
		CASE ELSE
			pgm_err$="Err No. "+STR$(err_no%)+" at Line "+STR$(err_line%)
			GOTO exit_handler
	END SELECT

exit_handler:
	BoxIndex%=1
	CALL EasyAlert("***** Program Error *****",pgm_err$,which%)
	IF which%=2 THEN
		WINDOW OUTPUT 1
		CLOSE
		RESUME quit
	END IF
	WINDOW OUTPUT 1
	CLOSE
	ON ERROR GOTO error_handler
	RESUME recover

break_handler:
	BoxIndex%=1
	BREAK OFF
	CALL EasyAlert("Control-C Break","Exit Program?",which%)
	IF which%=1 THEN
		ON BREAK GOSUB break_handler
		BREAK ON
		CLS
		GOTO recover
	END IF
	CLOSE
	GOTO quit
RETURN
