Version: 17.07
Supported Since: 17.01
An On Error Switch processing element used in combination with one or more Error Case processing elements, is
considered as an Error Switch-Case processor. Theoretically the behaviour of this is similar to the use of multiple
catch
blocks in a high level programming language such as Java, where this processor can be used as the error handler
for a particular processing element and it can direct the message contexts to different error handling branches based on the
last unhandled exception/error it encountered.
In order to use this processing element, you must first select the Regular Error Handling Processors dependency from the processor list when you are creating an empty Ultra project. If you have already created a project, you can add this dependency via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Processors list, select the Regular Error Handling Processors dependency. |
Cases |
All the Error Case elements should be connected to this outport. They will be evaluated in the ascending order
of their Order value and the message context will be sent to the first case element that evaluates to |
Default |
The message context will be sent to this outport if none of the case values evaluated to |
On Exception |
The message context will be sent to this outport if any exception occurred while processing |
On match |
The message context will be sent to this outport if the value of this case element evaluates to |
On Exception |
The message context will be sent to this outport if any exception occurred while processing |
Throwable class name * |
Basic |
The full class name of the throwable that can be handled by this case branch. This class must be either |
Match exact class * |
Basic |
Whether to match only the throwables which are of exactly the specified type. If set to false, any throwable which is a
subclass of the specified type will also be matched. Default value for this property is |
Order * |
Basic |
The order in this case branch should be evaluated by the On Error Switch element. The case branches will be evaluated
in the ascending order of this value and the message context will be sent to the first case element that evaluates to
|
In the following use case, a custom processing element is used to execute a specific business logic inside an integration
flow. This processing element expects a set of pre-defined transport headers with each message and it will throw an
IllegalArgumentException
in case any of those headers are missing. Even if all the headers are present, there is a
possibility of any other RuntimeException
occurring if the processing logic failed due to some other reason.
Therefore requirement is to handle IllegalArgumentExceptions
in a specific error processing branch, while all the other
RuntimeExceptions
are handled in a separate error branch. If there are any other errors rather than RuntimeExceptions
,
the message flow should be simply marked as failed.
The Java language representation of this scenario will look as below.
try {
// Execute business logic
} catch (IllegalArgumentException illArgException) {
// Handle through specific error flow
} catch (RuntimeException runtimeException) {
// Handle through generic error flow
} catch (Throwable throwable) {
// Mark message flow as failed
}
To achieve this, the On Error outport of the Custom processing element is connected to an On Error Switch element, so that the message context will be handed over to that On Error Switch in case of any exception or error. This On Error Switch element has 2 Error Case elements connected to its Cases outport and they are configured as follows.
Throwable class name : java.lang.IllegalArgumentException
Match exact class : false
Order : 1
The Throwable class name of this element is set as java.lang.IllegalArgumentException
and the Match exact class
property is set as false
so that this case branch will be evaluated as true
if an IllegalArgumentException
or any of its child exceptions has been occurred. Then the Order property is set to 1
so that this case branch will
be evaluated first by the switch element (which is similar to defining this as the first catch
block). The On Match
outport of this case is connected to the first element of the specific error handling flow that handles IllegalArgumentExceptions
.
Throwable class name : java.lang.RuntimeException
Match exact class : false
Order : 2
The Throwable class name of this element is set as java.lang.RuntimeException
and the Match exact class
property is set as false
so that this case branch will be evaluated as true
if an RuntimeException
or any of its
child exceptions has been occurred. But since IllegalArgumentException
is also a RuntimeException
, it is required to
evaluate this case branch after the 1st case, so that the message contexts with IllegalArgumentExceptions
are not handed
over to this branch. To achieve that behaviour, the Order property is set to 2
so that this case branch will be evaluated
after the 1st case which has an order value of 1
. The On Match outport of this case is connected to the first element
of the generic error handling flow that handles all other RuntimeExceptions
except IllegalArgumentExceptions
.
Since we need to simply mark the message flow as failed for other errors, the Default outport of the On Error Switch is connected to an Exceptional Flow End element.