Mule provides different approaches to handling errors. You can set exception strategies for connectors, models, and individual services. You can use the exception router to specify where the message goes when an error occurs. And you can use the exception type filter for fine-grained control. Following is an introduction to these approaches.
Exception strategies are used to handle exception conditions when an error occurs during the processing of a message. Exception strategies are used by components and connectors. You can set exception strategies in the following places:
- On the connector to set a common exception strategy for all endpoints that use the connector
- On a model to set a common exception strategy for all services within that model
- On a service to set an exception strategy for the components within that service.
Exception strategies set on the service or the model are used to handle component exceptions. These are exceptions that occur during the processing of a message through Mule and include all exceptions other than system exceptions such as initializing/disconnecting connections. Typically, you customize the exception handler to control how component exceptions are logged and routed.
Exception strategies set on the connector can be considered as fallback exception strategies that catch exceptions that occur before the connector has started or for connectors that haven’t got an association with a service and therefore cannot use a service exception strategy. Typically, you can’t do much more than log these exceptions. Therefore, you do not need to customize connector strategies, but you can configure them to route exceptions to a common error queue.
When an exception occurs, the exception-based router determines where the message goes. You can have multiple endpoints specified on the exception-based router, so that if the first endpoint fails with a FatalConnectionException, the next endpoint is tried, and then the next. If all endpoints fail, a routing exception is thrown. Note that the exception-based router will override the endpoint mode to synchronous while looking for a successful send, and it will resort to using the endpoint’s mode for the last item in the list.
Following is an example of configuring the exception-based router:
For more information on filters, see Using Filters in the Mule User’s Guide.