It's simple to update the unit test [1], so it looks like the following and
it runs successful:

public class OnExceptionHandledTest extends ContextTestSupport {

    public void testHandled() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:handled");
        mock.expectedBodiesReceived("Hello World");
        mock.message(0).property(Exchange.EXCEPTION_CAUGHT).isNotNull();

mock.message(0).property(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IOException.class);

mock.message(0).property(Exchange.EXCEPTION_CAUGHT).convertTo(String.class).isEqualTo("Forced");

        template.sendBody("direct:start", "Hello World");

        assertMockEndpointsSatisfied();
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                onException(IOException.class)
                    .handled(true)
                    .to("mock:handled");

                from("direct:start")
                    .throwException(new IOException("Forced"));
            }
        };
    }
}

[1]
https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob;f=camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionHandledTest.java;h=565b942c5f07e8be2761436398ba03ed040361ed;hb=HEAD

Best,
Christian
-----------------

Software Integration Specialist

Apache Camel committer: https://camel.apache.org/team
V.P. Apache Camel: https://www.apache.org/foundation/
Apache Member: https://www.apache.org/foundation/members.html

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Sun, Jun 30, 2013 at 12:36 PM, Tarun Kumar <agrawal.taru...@gmail.com>wrote:

> Hi, any help will be highly appreciated. In my case, why is my bean
> exception not being propagated to camel route?
>
>
> On Fri, Jun 28, 2013 at 12:38 PM, Tarun Kumar <agrawal.taru...@gmail.com
> >wrote:
>
> > Yes, i have looked all unit tests.
> >
> > In my case, abc method throws IOException.
> > when i surround this bean class with .doTry and
> > .doCatch(IOException.class) blocks, it never goes inside .doCatch(). Is
> > exception from "abc" method is not being propagated to camel route? Why
> > does it not go inside doCatch()?
> >
> > My other ques is how does it know what is inside doCatch block? Does it
> > find it out based on indentation?
> > .doTry().bean()
> > .doCatch()
> > .bean(A.class, "abc")
> > .bean(B.class, "abd")
> >
> > how does it know whether bean call to B.class is inside doCatch or not?
> >
> >
> >
> >
> > On Fri, Jun 28, 2013 at 2:52 AM, Christian Müller <
> > christian.muel...@gmail.com> wrote:
> >
> >> I cannot believe it.
> >> Did you had a look at our unit tests [1]?
> >>
> >> [1]
> >>
> >>
> https://git-wip-us.apache.org/repos/asf?p=camel.git;a=tree;f=camel-core/src/test/java/org/apache/camel/processor/onexception;h=0b1ada52abb078e9e427b75cd362107557507ffc;hb=HEAD
> >>
> >> Best,
> >> Christian
> >> -----------------
> >>
> >> Software Integration Specialist
> >>
> >> Apache Camel committer: https://camel.apache.org/team
> >> V.P. Apache Camel: https://www.apache.org/foundation/
> >> Apache Member: https://www.apache.org/foundation/members.html
> >>
> >> https://www.linkedin.com/pub/christian-mueller/11/551/642
> >>
> >>
> >> On Thu, Jun 27, 2013 at 10:14 AM, Tarun Kumar <
> agrawal.taru...@gmail.com
> >> >wrote:
> >>
> >> > My route configure method looks like this:
> >> >
> >> > public void configure() {
> >> >
> >> >
> >>
>  onException(IOException.class).handled(true).bean(ExceptionHandler.class,
> >> > "handleException");
> >> >
> >> >    from().process().bean(firstBean.class, "abc").process().end();
> >> > }
> >> >
> >> > "abc" method of firstBean throws IOException, still, "handleException"
> >> > method of ExceptionHandler class is not being invoked. What can be the
> >> > reason?
> >> >
> >>
> >
> >
>

Reply via email to