Q. How does ScriptBasic handle runtime errors?
A. ScriptBasic uses exception handling like most Basic languages. See specifics bellow.
ON ERROR GOTO ErrorTrap
ERROR 1
PRINT "This won't print\n"
ErrorTrap:
PRINT "This is the error message.\n"
END
To turn off error handling use the the following directive.
ON ERROR GOTO NULL
The
RESUME directive will retry the same statement that cause the error.
The
RESUME NEXT will execute the next statement after the one that caused the error.
The
RESUME label will resume execution of the next statement following the provided label.
ERROR 0 clears the last error value but doesn't turn off error handling or change the resume point.
The
ON ERROR RESUME label will resume execution following the provided label.
The
ON ERROR RESUME NEXT will try to execute the statement after the one that caused the error.
Error Codes0 = No error
1 = Memory error
2 = Function can not return a whole array
3 = Division by zero or other calculation error
4 = Argument to operator is undefined
5 = The command or sub was called the wrong way
6 = There are not enough arguments for the module function.
7 = The argument passed to a module function is not the correct type.
8 = The argument passed to a module function is out of acceptable range.
9 = The module experiences difficulties reading the file
10 = The module experiences difficulties writing the file.
11 = The module experiences difficulties handling the file.
12 = There is a circular reference in memory.
13 = The module can not be unloaded, because it was not loaded.
14 = Some modules were active and could not be unloaded.
15 = The module can not be unloaded, because it is currently active.
16 = The requested module can not be loaded.
17 = The requested function does not exist in the module.
18 = The module did not initialize correctly
19 = The module was developed for a different version of ScriptBasic.
20 = File number is out of range, it should be between 1 and 512
21 = The file number is already used.
22 = The file can not be opened.
23 = The file is not opened.
24 = The lock type is invalid.
25 = The print command failed. The file may be locked by another process.
26 = Directory can not be created.
27 = The directory or file could not be deleted.
28 = Command is not implemented and no currently loaded extension module defined behaviour for it
29 = The character can not be a joker or wild card character.
30 = The code tried to execute a resume while not being in error correction code.
31 = The directory name in open directory is invalid.
32 = Invalid option for directory open.
33 = The directory can not be opened.
34 = The record length is invalid in the open statement (undefined, zero or negative)
35 = The current directory can not be retrieved for some reason.
36 = The directory name in chdir can not be undef.
37 = Cannot change the current working directory to the desired directory.
38 = The command RETURN can not be executed, because there is no where to return.
39 = The argument for the function address is invalid.
40 = The attribute value or symbol is invalid in the set file command.
41 = The user does not exist.
42 = The chown command is not supported on Win95 and Win98
43 = Can not change owner.
44 = The file name is invalid.
45 = Setting the create time of the file has failed.
46 = Setting the modify time of the file has failed.
47 = Setting the access time of the file has failed
48 = The specified time format is invalid
49 = The time is not valid, cannot be earlier than January 1, 1970. 00:00
50 = Extension specific error: (ext. error code)
51 = The operation can be done on files only and not on sockets.
52 = The embedding application tried to start the code at an invalid location
53 = Mandatory argument is missing
54 = Subprocess did not finish within time limits
55 = The module can not be unloaded
56 = The preprocessor said to abort program compilation or execution.
User Guide - Error Handling