Error Handling
When an error occurs in a SPEL+ function, you can cause execution to be transferred to an error handling routine for processing the error. The routine must be inside a function definition.
The table on the next page shows the program instructions that are used for error handling.
Item | Description |
---|---|
OnErr | Use the OnErr statement to define the location of the error handling routine. |
Err | Use Err to retrieve the number for the current error status. Use this in the error handling routine to determine which error has occurred. |
Error | Generate a user defined error which can be caught by an error handler. |
Era | Use Era to retrieve the axis number for which the error occurred. This is normally used in the error handling routine. |
Erl | Use Erl to retrieve the line number in which the error occurred. This is normally used in the error handling routine. |
Ert | Use Ert to retrieve the task number in which the error occurred. This is normally used in the error handling routine. |
ErrMsg$ | Use ErrMsg$ to retrieve the error message associated with a specified error number. |
Errb | Use Errb to retrieve the robot number in which the error occurred. This is normally used in the error handling routine. |
User Errors
You can define your own error messages by using the User Error Editor which is available from the Tools Menu. See details below.
[User Error Editor] (Tools Menu)
Example:
The following example shows a simple error handling routine. When an error occurs, program execution goes to the ErrHandler label, where the error handler starts. The error number is displayed and the operator is asked to continue or not. If the operator enters "N" then the program executes the Quit All statement to end the program.
Function Main
String cont$
Integer i
OnErr Goto Errhandler
For i = 1 To 10
Jump P(i)
Next i
Exit Function
' *** Error handler ***
Errhandler:
enum = Err
Print "Error #", enum, " occurred"
Print "Continue (Y or N)?"
Line Input cont$
Select cont$
Case "y", "Y"
EResume Next
Default
Quit All
Send
Fend