ERR: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "The ERR function returns the last QBasic error code number. {{PageSyntax}} : {{Parameter|errorNum%}} = ERR {{PageDescription}} * If there is no error, the function returns 0 * Can be used in an error handling routine to report the last error code number. {{PageExamples}} ''Example:'' Simulating an error to test a program error handler that looks for a "Subscript out of range" error. {{CodeStart}} '' '' {{Cl|ON ERROR}} {{Cl|GOTO}} handler {{Cl|IF...THEN|IF...")
 
No edit summary
 
Line 1: Line 1:
The [[ERR]] function returns the last QBasic error code number.  
The [[ERR]] function returns the last QBasic error code number.




Line 13: Line 13:
{{PageExamples}}
{{PageExamples}}
''Example:'' Simulating an error to test a program error handler that looks for a "Subscript out of range" error.
''Example:'' Simulating an error to test a program error handler that looks for a "Subscript out of range" error.
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|ON ERROR}} {{Cl|GOTO}} handler
{{Cl|ON ERROR}} {{Cl|GOTO}} handler


Line 30: Line 30:
   {{Cl|SYSTEM}}
   {{Cl|SYSTEM}}
{{Cl|END IF}}
{{Cl|END IF}}
{{Cl|RESUME}} {{Cl|NEXT}}              'RESUME can only be used in error handlers '' ''
{{Cl|RESUME}} {{Cl|NEXT}}              'RESUME can only be used in error handlers
{{CodeEnd}}
{{CodeEnd}}



Latest revision as of 01:34, 23 January 2023

The ERR function returns the last QBasic error code number.


Syntax

errorNum% = ERR


Description

  • If there is no error, the function returns 0
  • Can be used in an error handling routine to report the last error code number.


Examples

Example: Simulating an error to test a program error handler that looks for a "Subscript out of range" error.

ON ERROR GOTO handler

IF x = 0 THEN ERROR 111  'simulate an error code that does not exist
x = x + 1
IF x THEN ERROR 9        'simulate array boundary being exceeded

END

handler:
PRINT ERR, _ERRORLINE
BEEP
IF ERR = 9 THEN
  PRINT "The program has encountered an error and needs to close! Press a key!"
  K$ = INPUT$(1)
  SYSTEM
END IF
RESUME NEXT               'RESUME can only be used in error handlers


See also



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