Trapping Errors
If you attempt an invalid operation from the keyboard, the operation is not executed and an error message
appears. For example, if you execute + with a vector and a real number on the stack, the hp49g+/hp48gII
returns the message + Error: Bad Argument Type and returns the arguments to the stack (if Last
Arguments is enabled).
In a program, the same thing happens, but program execution is also aborted. If you anticipate error conditions,
your program can process them without interrupting execution.
For simple programs, you can run the program again if it stops with an error. For other programs, you can
design them to trap errors and continue executing. You can also create user-defined errors to trap certain
conditions in programs. The error trapping commands are located in the PRG ERROR menu.
Causing and Analyzing Errors
Many conditions are automatically recognized by the hp49g+/hp48gII as error conditions– and they're
automatically treated as errors in programs.
You can also define conditions that cause errors. You can cause a user-defined error (with a user-defined error
message) — or you can cause a built-in error. Normally, you'll include a conditional or loop structure with a test
for the error condition — and if it occurs, you'll cause the user-defined or built-in error to occur.
To cause a user-defined error to occur in a program:
1. Enter a string (with "" delimiters) containing the desired error message.
2. Enter the DOERR command (PRG ERROR menu).
To artificially cause a built-in error to occur in a program:
1. Enter the error number (as a binary integer or real number) for the error.
2. Enter the DOERR command (PRG ERROR menu).
If DOERR is trapped in an IFERR structure (described in the next topic), execution continues. If it's not
trapped, execution is abandoned at the DOERR command and the error message appears.
To analyze an error in a program:
To get the error number for the last error, execute ERRN (PRG ERROR menu).
!
To get the error message for the last error, execute ERRM (PRG ERROR menu).
!
To clear the last-error information, execute ERR0 (PRG ERROR menu).
!
The error number for a user-defined error is #70000h. See the list of built-in error numbers in appendix A,
"Error and Status Messages".
Example:
The following program aborts execution if the list in level 1 contains three objects.
«
OBJ
IF 3 ==
THEN "3 OBJECTS IN LIST" DOERR
END
»
The following table summarizes error trapping commands.
1-32 RPL Programming