11 Error handling
This chapter covers
- Understanding error handling
- Knowing where and when Camel’s error handling applies
- Using the various error handlers in Camel
- Using redelivery policies
- Handling exceptions with
onException
- Reusing error handlers in all your routes
- Performing fine-grained control of error handling
You’ve now reached the halfway mark of this book, and we’ve covered a lot of ground. But what you’re about to embark on in this chapter is one of the toughest topics in integration: how to deal with the unexpected.
Writing applications that integrate disparate systems is a challenge when it comes to handling unexpected events. In a single system that you fully control, you can handle these events and recover. But systems that are integrated over the network have additional risks: the network connection could be broken, a remote system might not respond in a timely manner, or it might even fail for no apparent reason. Even on your local server, unexpected events can occur, such as the server’s disk filling up or the server running out of memory. Regardless of which errors occur, your application should be prepared to handle them.
In these situations, log files are often the only evidence of the unexpected event, so logging is important. Camel has extensive support for logging and for handling errors to ensure that your application can continue to operate.