Apache Camel:errorHandler vs onException?

10 java error-handling exception-handling apache-camel

有什么区别:

<camel:errorHandler id="deadLetterErrorHandler" type="DeadLetterChannel" 
        deadLetterUri="log:dead">

<camel:camelContext errorHandlerRef="deadLetterErrorHandler">
    ...
</camel:camelContext>
Run Code Online (Sandbox Code Playgroud)

和:

<onException>
    ...
</onException>
Run Code Online (Sandbox Code Playgroud)

根据这篇文章,将它们结合使用是一种"强大的组合".怎么会这样?他们每个人扮演什么角色,他们如何相互补充?

Kei*_*ith 17

将errorHandler被用来处理任何未捕获Exception该获取消息的路由和处理过程中抛出.相反,onException用于Exception在抛出特定类型时处理它们.看看这篇文章,了解如何使用onException.

  • 所以如果我写`onException(Throwable.class)`我基本上实现了`errorHandler`? (5认同)