You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Remi Malessa <re...@llgc.org.uk> on 2011/01/18 16:20:39 UTC

Hi.
Could you please explain me what is the difference in handling an 
exception with two methods below?

1) I use <handled/> :

<bean id="readException" 
class="my.camel.package.ReadMessageExceptionClass"/>
.
.
.
<onException>
<exception>my.camel.package.ErrorFoundException</exception>
<handled><static>true</static><handled>
<bean ref="readException"/>
<to uri="activemq:read_error_queue"/>
</onException>

2) I don't use <handled/>

<onException>
<exception>my.camel.package.ErrorFoundException</exception>
<to uri="class:my.camel.package.ReadMessageExceptionClass"/>
<to uri="activemq:read_error_queue"/>
</onException>


As far as I tested the two above, the results from both methods are the 
same..., but are they ?
The class my.camel.package.ReadMessageExceptionClass, returns a message 
, with text body , saying what was the
exception and the message body.

Thanks
Remi


Re:

Posted by Remi Malessa <re...@llgc.org.uk>.
On 01/19/2011 01:54 PM, Claus Ibsen wrote:
> Yeah most camel consumers will just log the exception. They have a
> ExceptionHandler which you can customize.
> However some like JMS consumer will rollback if its transacted, and
> the file consumer will lave the file as is, and try it again on next
> poll (it has a moveFailed option to move the file to some other
> directory on rollback).
Got it. Thanks.

Remi

Re:

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jan 19, 2011 at 2:22 PM, Remi Malessa <re...@llgc.org.uk> wrote:
> On 01/19/2011 10:45 AM, Claus Ibsen wrote:
>>
>> See figure 5.5. When handled=true, the caused exception will be
>> removed from the exchange, and the route consumer will not "detect"
>> any exceptions caused processing the exchange.
>>
>> When handled=false, the caused exception will be placed on the
>> exchange, and the route consumer will "detect" the exception and can
>> react for example by rolling back. This is consumer specific what
>> action they do on detecting an exception.
>
> Alright, so if there is no handle=true and no exception handling implemented
> in the
> consumer, it can even skip/ignore the message ?
>

Yeah most camel consumers will just log the exception. They have a
ExceptionHandler which you can customize.
However some like JMS consumer will rollback if its transacted, and
the file consumer will lave the file as is, and try it again on next
poll (it has a moveFailed option to move the file to some other
directory on rollback).



> Remi
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re:

Posted by Remi Malessa <re...@llgc.org.uk>.
On 01/19/2011 10:45 AM, Claus Ibsen wrote:
> See figure 5.5. When handled=true, the caused exception will be
> removed from the exchange, and the route consumer will not "detect"
> any exceptions caused processing the exchange.
>
> When handled=false, the caused exception will be placed on the
> exchange, and the route consumer will "detect" the exception and can
> react for example by rolling back. This is consumer specific what
> action they do on detecting an exception.
Alright, so if there is no handle=true and no exception handling 
implemented in the
consumer, it can even skip/ignore the message ?

Remi

Re:

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jan 19, 2011 at 11:32 AM, Remi Malessa <re...@llgc.org.uk> wrote:
>
>
>
>
>
>
> On 01/19/2011 01:51 AM, Hadrian Zbarcea wrote:
>>
>> If you don't have the Camel in Action book (please don't interpret the
>> previous answer as a request to buy the book) you can find more details
>> about exception handling here:
>> http://camel.apache.org/exception-clause.html. If you are curious to look at
>> the code, look at how CatchProcessor.handles(Exchange) is implemented and
>> used.
>
> Thanks Hadrian. Ha ha. I did think it was an invite to buy the book :-) I've
> looked at the web page as well, thanks.
>
>> You didn't post your throwing code, but it looks like camel found an exact
>> match.
>
> Yes, the code always throws "my.camel.package.ErrorFoundException".
>
>>  If no handled expression is defined, the exception is considered handled
>> by default, which explains why the behavior you see is the same.
>
> The book says "(...)whereas onException will, by default, not handle it.
> That’s why you use handled(true) (#1) to
> instruct Camel to handle this exception."
> I wonder if there's an advantage of using <handled/> in one of my examples ?
> Is it any better then the other ?
>

See figure 5.5. When handled=true, the caused exception will be
removed from the exchange, and the route consumer will not "detect"
any exceptions caused processing the exchange.

When handled=false, the caused exception will be placed on the
exchange, and the route consumer will "detect" the exception and can
react for example by rolling back. This is consumer specific what
action they do on detecting an exception.



>> Cheers,
>> Hadrian
>
> Thanks
> Remi
>
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re:

Posted by Remi Malessa <re...@llgc.org.uk>.





On 01/19/2011 01:51 AM, Hadrian Zbarcea wrote:
> If you don't have the Camel in Action book (please don't interpret the previous answer as a request to buy the book) you can find more details about exception handling here: http://camel.apache.org/exception-clause.html. If you are curious to look at the code, look at how CatchProcessor.handles(Exchange) is implemented and used.
Thanks Hadrian. Ha ha. I did think it was an invite to buy the book :-) 
I've looked at the web page as well, thanks.

> You didn't post your throwing code, but it looks like camel found an exact match.
Yes, the code always throws "my.camel.package.ErrorFoundException".

>   If no handled expression is defined, the exception is considered handled by default, which explains why the behavior you see is the same.
The book says "(...)whereas onException will, by default, not handle it. 
That’s why you use handled(true) (#1) to
instruct Camel to handle this exception."
I wonder if there's an advantage of using <handled/> in one of my 
examples ? Is it any better then the other ?

> Cheers,
> Hadrian

Thanks
Remi


Re:

Posted by Hadrian Zbarcea <hz...@gmail.com>.
If you don't have the Camel in Action book (please don't interpret the previous answer as a request to buy the book) you can find more details about exception handling here: http://camel.apache.org/exception-clause.html. If you are curious to look at the code, look at how CatchProcessor.handles(Exchange) is implemented and used.

You didn't post your throwing code, but it looks like camel found an exact match. If no handled expression is defined, the exception is considered handled by default, which explains why the behavior you see is the same. There is more than meets the eye when it comes to exception handling. Spending a bit of time to understand how it works is well worth the effort.

Cheers,
Hadrian


On Jan 18, 2011, at 10:26 AM, Claus Ibsen wrote:

> Hi
> 
> Read chapter 5 in the Camel in Action book, it covers all about error handling.
> 
> 
> On Tue, Jan 18, 2011 at 4:20 PM, Remi Malessa <re...@llgc.org.uk> wrote:
>> Hi.
>> Could you please explain me what is the difference in handling an exception
>> with two methods below?
>> 
>> 1) I use <handled/> :
>> 
>> <bean id="readException"
>> class="my.camel.package.ReadMessageExceptionClass"/>
>> .
>> .
>> .
>> <onException>
>> <exception>my.camel.package.ErrorFoundException</exception>
>> <handled><static>true</static><handled>
>> <bean ref="readException"/>
>> <to uri="activemq:read_error_queue"/>
>> </onException>
>> 
>> 2) I don't use <handled/>
>> 
>> <onException>
>> <exception>my.camel.package.ErrorFoundException</exception>
>> <to uri="class:my.camel.package.ReadMessageExceptionClass"/>
>> <to uri="activemq:read_error_queue"/>
>> </onException>
>> 
>> 
>> As far as I tested the two above, the results from both methods are the
>> same..., but are they ?
>> The class my.camel.package.ReadMessageExceptionClass, returns a message ,
>> with text body , saying what was the
>> exception and the message body.
>> 
>> Thanks
>> Remi
>> 
>> 
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/


Re:

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Read chapter 5 in the Camel in Action book, it covers all about error handling.


On Tue, Jan 18, 2011 at 4:20 PM, Remi Malessa <re...@llgc.org.uk> wrote:
> Hi.
> Could you please explain me what is the difference in handling an exception
> with two methods below?
>
> 1) I use <handled/> :
>
> <bean id="readException"
> class="my.camel.package.ReadMessageExceptionClass"/>
> .
> .
> .
> <onException>
> <exception>my.camel.package.ErrorFoundException</exception>
> <handled><static>true</static><handled>
> <bean ref="readException"/>
> <to uri="activemq:read_error_queue"/>
> </onException>
>
> 2) I don't use <handled/>
>
> <onException>
> <exception>my.camel.package.ErrorFoundException</exception>
> <to uri="class:my.camel.package.ReadMessageExceptionClass"/>
> <to uri="activemq:read_error_queue"/>
> </onException>
>
>
> As far as I tested the two above, the results from both methods are the
> same..., but are they ?
> The class my.camel.package.ReadMessageExceptionClass, returns a message ,
> with text body , saying what was the
> exception and the message body.
>
> Thanks
> Remi
>
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/