Book Image

Mastering Apache Camel

By : Bilgin Ismet Ibryam, Jean Baptiste Onofre, Jean-Baptiste Onofré
5 (1)
Book Image

Mastering Apache Camel

5 (1)
By: Bilgin Ismet Ibryam, Jean Baptiste Onofre, Jean-Baptiste Onofré

Overview of this book

Table of Contents (15 chapters)
Mastering Apache Camel
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 any onException or...