Determining the Cause of the Error

The error handling code in a TRY statement can determine the cause of the error by inspecting the values of the task attributes PRIORHISTORY, PRIORHISTORYTYPE, PRIORHISTORYCAUSE, and PRIORHISTORYREASON. These task attributes store the values that HISTORY, HISTORYTYPE, HISTORYCAUSE, and HISTORYREASON would have had if the process had been terminated by the error.

The following example shows how TRY statement error code could use CASE statements to interrogate the PRIORHISTORYCAUSE and PRIORHISTORYREASON task attributes:

TRY [: PROTECTED ]                                               
  <statement or expression>                                      
ELSE                                                             
  BEGIN                                                          
  CASE MYSELF.PRIORHISTORYCAUSE OF                                    
    BEGIN                                                        
      0: % If PROTECTED, this value indicates a GO TO            
         % is exiting to outside the TRY statement.           
         % Perform any necessary cleanup.                     
         LIBERATE(E1);                                           
      VALUE(OPERATORCAUSEV):                                     
         CASE MYSELF.PRIORHISTORYTYPE OF                              
         BEGIN                                                   
         VALUE(JUSTDSEDV): DISPLAY(“DO NOT ATTEMPT TO DS ME”);   
              VALUE(RSVPV): DISPLAY(“WRONG ANSWER”);             
         END;                                                    
      VALUE(PROGRAMCAUSEV):                                      
         CASE MYSELF.PRIORHISTORYREASON OF                            
         BEGIN                                                   
              VALUE(DEATHINFAMILYV):                             
              VALUE(CRITICALBLOCKV): LIBERATE(E1);               
         END;                                                    
      ELSE:                                                      
    END;                                                         
  END;