I have some problems when handle the exception between multiple routes.
As a java developer’s perspective, I want to extract some common logic to a common route so that other routes can call the common route directly without containing the common logic everywhere.(like the route-version function call) But when it comes to the error handling, I found it’s a little tricky.
For instance:
//main logic 1
from("direct:route1")
.doTry()
.to("direct:common")
.doCatch(Exception.class)
.log("Error in route1")
.end()
//main logic 2
from("direct:route2")
.doTry()
.to("direct:common")
.doCatch(Exception.class)
.log("Error in route2")
.end()
//common logic
from("direct:common")
.to("mock:commonlogic")
The problem is when some exception thrown from the “mock:commonlogic” endpoint, the exception won’t be caught by doTry…doCatch blocks defined both in route1 and route2. It seems like the exception just can be handled in the common route scope. But what I want is the common route just ‘throws out’ the exception and the ‘caller’ routes handle it all by themselves. Is there any way to do that?
Thanks
You need to disable error handling in the common route.Then any exceptions thrown from the common route, is not handled by any error handler, and propagated back to the caller route, which has the try .. catch block.