Try, Catch, and Finally

Until now, we have used error handlers (most of the time the DefaultErrorHandler), which applies to all channels in the routes. You might want to square the exception handling to some part of a route.

It's similar to the try/catch/finally Java statements.

<route>
    <from uri="direct:start"/>
    <doTry>
        <process ref="processor"/>
        <to uri="direct:result"/>
        <doCatch>
            <!-- catch multiple exceptions -->
            <exception>java.io.IOException</exception>
            <exception>java.lang.IllegalStateException</exception>
            <to uri="direct:catch"/>
        </doCatch>
        <doFinally>
            <to uri="direct:finally"/>
        </doFinally>
    </doTry>
</route>

Camel error handling is disabled. When using doTry .. doCatch .. doFinally, the regular Camel error handler does not apply. This means ...

Get Mastering Apache Camel now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.