Handling Local Exceptions in Mule

A catch exception strategy can be defined to customize the way Mule handles messages with errors. A catch exception strategy catches all exceptions thrown within its flow and processes them, thereby overriding Mule’s implicit default exception strategy.

Mule’s catch exception strategy behavior is similar to a Java catch block, except that a new exception cannot be thrown or another exception cannot be caught within a catch exception strategy.
For local catch-exception-strategy, exception strategies can be configured on a per-flow basis. This is done by defining an exception strategy at the end of each flow definition.

Let’s start by configuring an exception strategy inside a flow. Let’s use a catch-exception-strategy that will catch and process all exceptions thrown in the flow

Here you can find one new element, the catch-exception-strategy. This element instructs the flow to respond with a String that summarizes the exception message, for any kind of error.

The graphical representation is shown below


The PriceCalculator java class source code

When you run the mule application, you will see below outputs on different inputs




Console Output

Thanks for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.