Using Catch Exception Strategy in MuleSoft ESB
From the technical center of excellence of Massil Technologies, our technology leaders make it easy to understand the complex situations you come across in Mule ESB from the experience of Massil Technologies to have countered them in their experience of working on client projects in real time. This blog addresses how to use Catch Exception Strategy in Mule ESB. This blog is a part of series of blogs being authored and published by Massil Technologies for the benefit of the IT community globally.
What is Catch Exception Strategy?
In Mule ESB, there is a strategy adopted to customize the way messages with errors are handled. The defined strategy to catch all exception that arises within its usual flow and process them, thereby overriding Mule ESBs implicit default exception strategy. This defined strategy is termed Catch Exception Strategy in Mule ESB.
To generalize the statement made, we can compare this to Java catch block. It cannot throw a new exception or catch another exception within a catch exception strategy.
When to Use:
Using Catch Exception Strategy design a unique approach for handling any message that may contain an error. You can also use it to:
Example of using Catch Exception Strategy in Mule ESB:
Let us try an example in AnyPoint Studio to understand this concept more clearly.
Create a project and search HTTP listener in Mule Palette and drag it to the Message flow and configure as follows:
Store the data in the variable which is coming from Payload as follows:
Let us create an Error to Caught the Catch Exception strategy. Search and Drag a variable connector from mule Palette to message flow & set the variable as given below:
In Http Listen, click on Error Handling to Expand. Now Search & Drag a catch exception strategy from mule Palette to message flow & keep it in Error Handling Expanded Area.
Drag Message Properties, keep it in catch exception strategy. Now set the http status in Message Properties as shown:
Keep the set payload after the message property to print the Error message.
Complete flow is here.
Run the project and after successful deployment hit some data from postman to see the results
Hope this article from Massil Technologies was useful for you. If you have any further queries on this topic, please reach out to email@example.com.