Java Mule:获取异常消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23343361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mule: getting a hold of the exception message
提问by Loic Duros
I have a default catch exception in Mule, and I'm trying to get access to the exception message, using a Mule expression: #[exception]
我在 Mule 中有一个默认的 catch 异常,我正在尝试使用 Mule 表达式访问异常消息:#[exception]
This doesn't seem to work, and I'm guessing that I'm trying to access the wrong variable? I'm trying to log it using logger and also run a custom component that takes in an exception message (as a string.)
这似乎不起作用,我猜我正在尝试访问错误的变量?我正在尝试使用记录器记录它并运行一个自定义组件,该组件接收异常消息(作为字符串)。
Thanks,
谢谢,
采纳答案by Charu Khurana
You can do #[exception.causedBy]
like
你可以#[exception.causedBy]
像
<choice-exception-strategy>
<catch-exception-strategy when="exception.causedBy(com.company.BusinessException)"> <!-- [1] -->
<jms:outbound-endpoint queue="dead.letter">
<jms:transaction action="ALWAYS_JOIN" />
</jms:outbound-endpoint>
</catch-exception-strategy>
<rollback-exception-strategy when="exception.causedBy(com.company.NonBusinessException)"> <!-- [2] -->
<logger level="ERROR" message="Payload failing: #[payload]"/>
</rollback-exception-strategy>
</choice-exception-strategy>
More details here
更多细节在这里
回答by Nicolas
Hi if you want to get the exception message using MEL you can also (in a Catch Exception Strategy) use the following expression.
嗨,如果您想使用 MEL 获取异常消息,您也可以(在捕获异常策略中)使用以下表达式。
#[exception.cause.message]
回答by Prathiba
In some cases the exception.cause
could be null
, hence advised to use the conditional to display the message:
在某些情况下exception.cause
可能是null
,因此建议使用条件来显示消息:
[(exception.cause!=null)?(exception.cause.message):exception]
This will prevent null pointer exception.
这将防止空指针异常。
回答by Nirmal- thInk beYond
Best way to get exception message (null safe) is :
获取异常消息(空安全)的最佳方法是:
#[exception.cause.?message or exception.cause]
#[exception.cause.?message or exception.cause]
回答by pulsar
exception.cause could be null so it could be handled like this:
exception.cause 可能为 null,因此可以这样处理:
#[exception.?cause.message or exception]