This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:onerror [2016/08/13 12:36] admin |
en:onerror [2020/02/28 10:46] (current) |
||
---|---|---|---|
Line 2: | Line 2: | ||
==== Format ==== | ==== Format ==== | ||
- | **onerror** [[labelprogamsyntax|label]] | + | **onerror** [[labelprogramsyntax|label]] |
==== Description ==== | ==== Description ==== | ||
- | Causes the [[GosubReturn|Gosub]] at [[labelprogamsyntax|label]] to be executed when a runtime error occurs. | + | Causes the [[GosubReturn|Gosub]] at [[labelprogramsyntax|label]] to be executed when a runtime error occurs. |
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]] | + | < |
+ | # test error trapping | ||
+ | onerror nicetrap | ||
+ | print 1 | ||
+ | next haha | ||
+ | print 2 | ||
+ | open 999, " | ||
+ | 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 | ||
+ | </ | ||
+ | will display\\ | ||
+ | < | ||
+ | 1 | ||
+ | trap and run - error on line 4 - error number 4 message Next without FOR () | ||
+ | 2 | ||
+ | trap and run - error on line 6 - error number 5 message Invalid File Number () | ||
+ | Runs Anyway | ||
+ | 3 | ||
+ | ERROR on line 12: Next without FOR | ||
+ | </ | ||
+ | |||
+ | See additional | ||
==== See Also ==== | ==== See Also ==== |