Error Trapping Rules
For BBj-specific information, see Symbolic Labels.
Programmers can handle certain errors within a program by "trapping" the error. The program can branch to a specific line to handle an error, or it can let PRO/5 deal with the error. The SETERR and SETESC verbs and the ERR=, END=, and DOM= clauses are designed to let the application program trap errors. The list below provides trapping rules for all errors except !ERROR=127 (escapes). PRO/5 checks for traps in the order listed:
-
If !ERROR=2 and there is an active END= clause then the END= branch is taken. END means "end of file."
-
If !ERROR=11 and there is an active DOM= clause, then the DOM= branch is taken. DOM means "duplicate or missing key."
-
If the error occurred while performing a built-in function which has an ERR= clause, then the function level ERR= branch is taken.
-
If the error occurred during an I/O statement or CALL statement with the statement level ERR= clause, then the statement level ERR= branch is taken.
-
If a SETERR clause is active, the SETERR branch is taken. PRO/5 saves the current SETERR value and resets SETERR to zero. RETRY restores the saved value.
If an error branch is taken, PRO/5 saves the current statement for a possible RETRY, overwriting any prior RETRY information. For this reason, errors and retries cannot be nested. However, if the error branch goes to the same line containing the error, PRO/5 does not save the RETRY information, leaving intact any prior RETRY information. This allows limited error handling within an error handling procedure.
If an untrapped error occurs in a public program, PRO/5 exits to the calling program and re-issues the error at that level. PRO/5 acts as if the error occurred within the CALL statement, and can pass a single error down through several levels of public programs.
In a workspace program, an untrapped error causes PRO/5 to go into console mode. PRO/5 prints the error number. If PRO/5 was already in console mode, nothing else is printed; otherwise, the offending line of code is listed. If the error code is !ERROR=30 or !ERROR=31, then only the line number displays.
!ERROR=127 Error Trapping Rules
-
If a SETESC is active, PRO/5 performs a GOSUB to the appropriate line and processing continues. The error handling routine should use a RETURN, as opposed to a RETRY, to resume processing at the statement with the error. Because PRO/5 stacks escape traps, you can nest !ERROR=127 traps.
-
If SETERR is active in a public program, PRO/5 takes a branch exactly as described in the preceding list for trapping other errors.
-
In normal mode, when users escape during a public program and the escape is not trapped, PRO/5 displays the line number and program name, then exits to the calling program and issues an !ERROR=39 at that level.
-
When users escape from a workspace program, PRO/5 goes into console mode, but does not display an error number. If the program was in run mode, the line containing the !ERROR=127 displays.
-
If PRO/5 is set to allow console mode within an active Public Program, it stays in the program and goes to console mode.