Programmer Guide > Writing Procedures and Functions > Error Handling in Procedures
  

Error Handling in Procedures
Whenever an error occurs during the execution of a user-written procedure, a description of the error is printed and execution of the procedure halts. You can change the environment that is restored after an error occurs with the ON_ERROR procedure. The four possible actions are:
*0—Stop at the statement in the procedure that caused the error, the default action.
*1—Return all the way back to the main program level.
*2—Return to the caller of the program unit which established the ON_ERROR condition.
*3—Return to program unit which established ON_ERROR condition.
If ON_ERROR is not called by a parent of the procedure in which an error occurs, the procedure is not exited, and the current variables are those of the halted procedure, not of the caller. To return to the calling unit, or to the single statement mode if the procedure was called from the single statement mode, enter RETURN or RETALL from the terminal.
Calling ON_ERROR from the main level or from a procedure sets the default error action for all modules called from that level. For example, to always return to the main level after an error, issue the statement:
ON_ERROR, 1
from the main level, or from your startup procedure.
Many library procedures issue an ON_ERROR, 2 call to return to their caller if an error occurs.
Error Signaling
Use the MESSAGE procedure in user-written procedures and functions to issue errors. For detailed information on this procedure, see "Error Signaling".
“Disappearing Variables”
PV-WAVE novices are frequently dismayed to find that all their variables have seemingly disappeared after an error occurs inside a procedure or function. The misunderstood subtlety is that after the error occurs PV-WAVE’s context is inside the called procedure, not in the main level. Typing RETURN or RETALL makes the lost variables reappear by bringing them back into scope.
RETALL is best suited for use when an error is detected in a procedure and you want to return immediately to the main program level despite nested procedure calls. RETALL issues RETURNs until the main program level is reached.

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.