Difference between revisions of "ON ERROR"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
Line 33: Line 33:
  
  
''See also:'' [[ERR]], [[ERL]], [[RESUME]]
+
''See also:'' [[ERR]], [[ERL]], [[RESUME]], [[ON...GOTO]]
  
  

Revision as of 03:25, 7 October 2009

ON ERROR is used with GOTO to designate a way to handle a program error.


Syntax: ON ERROR GOTO ErrorHandler


  • ON ERROR calls MUST be used in the main module code. It will also handle any subroutine errors!
  • ErrorHandler is a line label in the main module assigned to clean up or ignore an error.
  • Another ON ERROR call will override the previous one.
  • GOTO is required in the statement. Cannot use GOSUB !


Example: Using an error handler that ignores any error.

ON ERROR GOTO Errhandle
' Main module program code
SYSTEM ' end of program code
Errhandle:
PRINT ERR;
RESUME NEXT ' moves program to code following the error.


Explanation:

  • The ON ERROR statement is normally placed at the beginning of the main module code.
  • Errhandle is the line label referred to.
  • The handler prints the error code and attempts to use the next line of code.



See also: ERR, ERL, RESUME, ON...GOTO


See QB64: _ERRORLINE



Navigation:

Go to Keyword Reference - Alphabetical

Go to Keyword Reference - By usage