Have you ever thought “Boy, I wish I could create my own error system for my programs” before? With ON ERROR you can. This would be more useful for programs dealing with files because files can be accidentally deleted or moved around easily.
To install this neat feature, just add the below code to the top of your program:
ON ERROR GOTO [Err]
*Note: If you want you can change [Err] to anything you want
Now like any goto, add the branch label anywhere in your program.
[Err]Now, lets add some code for that label. The most common is a notice. When JB encounters an error, it will store the QBASIC error code into a special variable called Err and a description will be held in the string Err$.
[Err] notice “Error “;Err;”” + chr$(13) + Err$ end
And the code above is just a sample. You can even have your own error log!
Finally, here’s a list of error codes. Thanks for reading!
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