1.4.9 exceptionHandling

The exceptionHandling function block enables you to divert exceptions from the workflow's main processing course to a separate course, where exceptions are processed according to your needs.

exceptionHandling in Batch Workflows

For example: When a workflow occasionally aborts due to an exception in the APL code, use exceptionHandling to cancel the batch.

Example - Using exceptionHandling to cancel a batch

consume {
 int a = 1;
 int b = 0;
 debug("The following row will generate an exception");
 float c = a/b;
}
exceptionHandling {
 debug("Type: "+ exception.type);
 debug("Message: " + exception.message);
 debug("Stacktrace: " + exception.stackTrace);
 cancelBatch("Exception caught", exception); 
}

Note!

The exceptionHandling function block for batch workflows is a legacy statement that is retained for backward compatibility. It is recommended that you use try-catch, throw and finally statements instead. These are described in the next section. 

Exception Handling in Batch and Real-Time Workflows

The try-catch, throw and finally statements can be used to handle exceptions in batch and real-time.

You use a try-catch block if the statements within the try block might throw an exception. try-catch blocks can be nested. The try block is followed by a catch block, which specifies the type of exception that it handles. You can route any UDR with udrRoute within the catch block.

If an exception is thrown, the code jumps to the catch block, which in this case handles all Java class Exceptions. Note that the catch in this case does not catch Throwable Exceptions.

A throw block throws an exception to the catch block which handles the exception.

A finally block is at the end of a catch block and runs a clean-up.

Note!

 The use of these Exception Handling statements only applies to APL.

For example: When an exception is thrown due to division by zero, use the try-catch statement to catch the thrown exception. It is also possible to use the throw statement to throw the exception again. Use finally to ensure a clean-up is done.

Example - Using the try-catch statement

consume { 
    int b = 0;
    try { 
       debug("Hello: " + 100/b); 
    }
    catch (ExceptionDetails exception) { 
       debug("EXCEPTION: " + exception.message);
       // To throw exception caught, write 'throw exception'. 
       throw testCreate(); 
       // This will cause execution of the (legacy) exceptionHandling if declared (only available in batch workflows), otherwise 
       the workflow aborts.
    } 
    finally {
       debug("In finally clause " + b);
    }
}
ExceptionDetails testCreate() {
    ExceptionDetails ed = udrCreate(ExceptionDetails);
    ed.message = "DONE";
    return ed;
}

ExceptionDetails

The ExceptionDetails UDR stores the information for an exception that is caught in a catch block in batch or real-time.

FieldDescription

message (string)

The message included in the exception

stackTrace (string)The function call hierarchy from where the exception occurred
type (string)Type of exception
OriginalData (bytearray)This field is always empty.