AKD BASIC User Guide | 6 AKD BASIC Parameters, Operators, Statements
6.1.13 On Error GoTo
General Information
Type Statement
Description
On Error Goto allows you to define a run-time error handler to prevent run-time
errors from halting program execution.
Units N/A
Range N/A
Default
Value
N/A
Data Type N/A
Start Ver-
sion
TBD
Description
On Error Goto allows you to define a run-time error handler to prevent run-time errors from halt-
ing program execution. Different error handlers can be defined for different parts of the program.
An error handler is active from when the On Error Goto statement is executed until another one
is executed.
An error handler has the same structure as a subroutine, but must end with a Restart state-
ment. If the error handler does not end with a Restart statement then program execution will ter-
minate at the End Sub statement.
Using the form On Error Goto 0 disables any user defined run-time error handler and reinstalls
the default handler. Any subsequent run-time error will print an error message and halt the pro-
gram.
Errors occurring within the error handler are handled by the default error handler. This means
that they will halt program execution.
Example
dim Count as integer
Main
dim y as integer
if Count < 10 then
on error goto MyHandler
else
on error goto 0
end if
y = 0
pause(0.5)
y = 1/y
print "I'll never get here"
end main
Sub MyHandler
Count = Count+1
print Count
restart
End Sub
Related Topics
Kollmorgenâ„¢ | March 30, 2012 110