Checking which unhandled exception or fault occurred for a failed process instance

In a well-designed process, exceptions and faults are usually handled by a fault handler. If the process implements a two-way operation, you can retrieve information about a fault or handled exception from the fault name property of the process instance object. For faults, you can also retrieve the corresponding fault message using the getFaultMessage API.

About this task

If a process instance fails because of an exception that is not handled by any fault handler, you can retrieve information about the unhandled exception from the process instance object. By contrast, if a fault is caught by a fault handler, then information about the fault is not available. You can, however, retrieve the fault name and message and return to the caller by using a FaultReplyException exception.

Procedure

  1. List the process instances that are in the failed state.
    QueryResultSet result = 
         process.query("PROCESS_INSTANCE.PIID", 
                       "PROCESS_INSTANCE.STATE = 
                           PROCESS_INSTANCE.STATE.STATE_FAILED", 
                        (String)null, (Integer)null, (TimeZone)null); 
    This action returns a query result set that contains the failed process instances.
  2. Read the information for the unhandled exception.
    if (result.getEntities().size() > 0)
    {
      Entity entity = (Entity) result.getEntities().get(0);
      PIID piid = (PIID) entity.getAttributeValue("PIID");
      ProcessInstanceData pInstance = process.getProcessInstance(piid);
      
      ProcessException excp = pInstance.getUnhandledException();
      if ( excp instanceof RuntimeFaultException )
      {
       RuntimeFaultException xcp = (RuntimeFaultException)excp;
       Throwable cause = xcp.getRootCause();
      }
      else if ( excp instanceof StandardFaultException )
      {
       StandardFaultException xcp = (StandardFaultException)excp;
       String faultName = xcp.getFaultName();
      }
      else if ( excp instanceof ApplicationFaultException )
      {
       ApplicationFaultException xcp = (ApplicationFaultException)excp;
       String faultName = xcp.getFaultName();
      }     
    }

Results

Use this information to look up the fault name or the root cause of the problem.