User Tools

Site Tools


en:onerror

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:onerror [2016/01/01 22:41]
127.0.0.1 external edit
en:onerror [2020/02/28 10:46] (current)
Line 2: Line 2:
  
 ==== Format ==== ==== Format ====
-**onerror** //label//+**onerror** [[labelprogramsyntax|label]]
  
 ==== Description ==== ==== Description ====
-Causes the [[GosubReturn|Gosub]] at //label// to be executed or [[Subroutine|Subroutine]] to be called when an runtime error occurs.  Program control may be resumed at the next statement with a [[GosubReturn|Return]] statement in the subroutine.  Error traps are kept in a stack so that the last defined trap, that has not been removed with an [[offerror|OffError]] will be the active one.+Causes the [[GosubReturn|Gosub]] at [[labelprogramsyntax|label]] to be executed when runtime error occurs.  Program control may be resumed at the next statement with a [[GosubReturn|Return]] statement in the subroutine.  Error traps are kept in a stack so that the last defined trap, that has not been removed with an [[offerror|OffError]] will be the active one.
  
 You may not execute an OnError statement inside a [[Try|Try / Catch / End Try]] statement. You may not execute an OnError statement inside a [[Try|Try / Catch / End Try]] statement.
Line 11: Line 11:
 ==== Example ==== ==== Example ====
  
-See example of usage on [[Errorcodes|Error Codes]] and [[ThrowError|ThrowError]] pages.+<code> 
 +# test error trapping 
 +onerror nicetrap 
 +print 1 
 +next haha 
 +print 2 
 +open 999, "bogus.file" 
 +print "Runs Anyway" 
 + 
 +# test error trapping off and fail at any error (default) 
 +offerror 
 +print 3 
 +next hoho 
 +print "never get here" 
 + 
 +end 
 + 
 +nicetrap: 
 +# this is the nice error handler 
 +print "trap and run - error on line " + lasterrorline + " - error number " + lasterror + " message " + lasterrormessage + " (" + lasterrorextra + ")" 
 +return 
 +</code> 
 +will display\\ 
 +<code> 
 +
 +trap and run - error on line 4 - error number 4 message Next without FOR () 
 +
 +trap and run - error on line 6 - error number 5 message Invalid File Number () 
 +Runs Anyway 
 +
 +ERROR on line 12: Next without FOR  
 +</code> 
 + 
 +See additional example of usage on [[ThrowError|ThrowError]] page.
  
 ==== See Also ==== ==== See Also ====
Line 18: Line 51:
 ==== History ====  ==== History ==== 
 |0.9.6z|New To Version| |0.9.6z|New To Version|
 +|1.99.99.33|Removed the ability to use a subroutine for error trapping|
  
en/onerror.1451713298.txt.gz · Last modified: 2020/02/28 10:46 (external edit)