我希望从路由中捕获所有的异常。
我添加了以下的 OnException 代码:
onException(Exception.class).process(new MyFunctionFailureHandler()).stop();
然后,我创建了名为MyFunctionFailureHandler的类。
public class MyFunctionFailureHandler implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
Throwable caused;
caused = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
exchange.getContext().createProducerTemplate().send("mock:myerror", exchange);
}
}
很遗憾,它不起作用,我不知道原因。
如果有异常,程序必须停止。
我该怎么知道这段代码为什么不起作用!!
谢谢。