ERROR Codes

From QB64 Phoenix Edition Wiki
Revision as of 10:35, 29 January 2023 by RhoSigma (talk | contribs)
Jump to navigation Jump to search

This page lists all the error codes defined in QB64 that can occur in a program when running. Unless overridden with an ON ERROR handler, these result in a dialog box appearing. Due to legacy holdovers from previous BASIC dialects, not all of these errors may actually occur in a program (unless manually triggered with ERROR).

If you encounter an error while editing in the QB64 IDE or when compiling (especially a "C++ Compilation Failed" message), or believe your program is correct, please report the error at https://github.com/QB64-Phoenix-Edition/QB64pe/issues.

It's recommended to exclude (whitelist) the entire "qb64" respectively "qb64pe" folder from any real-time anti-virus scanning to prevent generic strange errors when editing or compiling.


Recoverable errors

These errors can be triggered in QB64, and may be caught by an ON ERROR handler. The default error handler gives the user option to continue program execution.

Code Description Possible Cause
2 Syntax error READ attempted to read a number but could not parse the next DATA item.
3 RETURN without GOSUB The RETURN statement was encounted without first executing a corresponding GOSUB.
4 Out of DATA The READ statement has read past the end of a DATA block. Use RESTORE to change the current data item if necessary.
5 Illegal function call A function was called with invalid parameters, in the wrong graphics mode or otherwise in an illegal fashion. Illegal Function gives some suggestions.
6 Overflow A numeric operation has resulted in a value beyond a variable's allowed range. See variable type.
7 Out of memory Generic out of memory condition.
9 Subscript out of range An array's upper or lower dimensioned boundary has been exceeded.
10 Duplicate definition An array created with DIM was redefined with DIM or REDIM.
13 Type mismatch A PRINT USING format string did not match the type of the supplied variables.
20 RESUME without error The RESUME statement was encountered outside of an ON ERROR error handler.
50 FIELD overflow The FIELD statement tried to allocate more bytes than were specified for the record length of a random access file.
51 Internal error Generic error
52 Bad file name or number A file handle was used that does not correspond to a valid opened file.
53 File not found File error, see below
54 Bad file mode A file operation was not compatible with the mode used in the OPEN statement.
55 File already open An OPEN statement attempted to use a file handle that is already in use. Consider using FREEFILE.
59 Bad record length The record length used for a RANDOM file was insufficient to perform the operation.
62 Input past end of file A file was read past its end. Ensure EOF is being correctly checked.
63 Bad record number The record (for RANDOM) or offset (for BINARY) is outside the allowed range.
64 Bad file name File error, see below
68 Device unavailable A serial port (COM device) failed to behave as expected
70 Permission denied File error, see below
75 Path/File access error File error, see below
76 Path not found File error, see below
258 Invalid handle An handle used for an image, sound, font etc. was invalid. Be sure to check the return values of functions like _LOADFONT and _LOADIMAGE.

Error handling of file operations varies between operating systems and is highly dependent on the exact circumstances. The errors marked "file error" above should all be equally treated as a generic failure to read or write from disk.


Critical errors

These errors can be triggered in QB64 but will not be caught by an ON ERROR handler. They are always fatal, causing the program to exit.

Code Description Notes
11 Division by zero Only relevant for integer division, and may not be caught on all operating systems.
256 Out of stack space Too many nested GOSUB calls.
257 Out of memory Generic out of memory condition.
259 Cannot find dynamic library file A .dll, .so or .dylib file referred to by DECLARE LIBRARY was not found.
260, 261 Sub/Function does not exist in dynamic library A function declared with DECLARE LIBRARY does not exist.
270 _GL command called outside of SUB _GL's scope
271 END/SYSTEM called within SUB _GL's scope
300 Memory region out of range Triggrered by _MEM commands
301 Invalid size Triggrered by _MEM commands
302 Source memory region out of range Triggrered by _MEM commands
303 Destination memory region out of range Triggrered by _MEM commands
304 Source and destination memory regions out of range Triggrered by _MEM commands
305 Source memory has been freed Triggrered by _MEM commands
306 Destination memory has been freed Triggrered by _MEM commands
307 Memory already freed Triggrered by _MEM commands
308 Memory has been freed Triggrered by _MEM commands
309 Memory not initialized Triggrered by _MEM commands
310 Source memory not initialized Triggrered by _MEM commands
311 Destination memory not initialized Triggrered by _MEM commands
312 Source and destination memory not initialized Triggrered by _MEM commands
313 Source and destination memory have been freed Triggrered by _MEM commands
314 _ASSERT failed See _ASSERT.
315 _ASSERT failed (check console for description) See _ASSERT.
502 to 518 Out of memory Generic out of memory condition.


Legacy errors

These errors will never be generated by a genuine error condition, and can only be triggered by explicit use of the ERROR command. They can all be caught by ON ERROR.

Code Description
1 NEXT without FOR
8 Label not defined
12 Illegal in direct mode
14 Out of string space
16 String formula too complex
17 Cannot continue
18 Function not defined
19 No RESUME
24 Device timeout
25 Device fault
26 FOR without NEXT
27 Out of paper
29 WHILE without WEND
30 WEND without WHILE
33 Duplicate label
35 Subprogram not defined
37 Argument-count mismatch
38 Array not defined
40 Variable required
56 FIELD statement active
57 Device I/O error
58 File already exists
61 Disk full
67 Too many files
69 Communication-buffer overflow
71 Disk not ready
72 Disk-media error
73 Feature unavailable
74 Rename across disks


Custom errors

Any code not listed above may be used as a custom error code with ERROR to signal other errors in your application. To avoid confusion, it is a good idea to start at error code 100 and go up from there.


Other Errors

  • Syntax errors: QB64 will display most statement syntax and parameter errors in the Status area below the editing area in the IDE. It may also show missing brackets or other syntax punctuation required. Check the keyword's syntax when necessary.
  • Memory errors: Loading many resources with a function like _LOADIMAGE and not freeing (e.g. _FREEIMAGE) can cause out of memory conditions, especially when executed in a loop.
  • CPU consumption: Loops will tend to use 100% of a processor by default. Consider using _LIMIT to restrict CPU usage.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link