6

I have a default catch exception in Mule, and I'm trying to get access to the exception message, using a Mule expression: #[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,

4

5 回答 5

9

在某些情况下exception.cause可能是null,因此建议使用条件来显示消息:

[(exception.cause!=null)?(exception.cause.message):exception]

这将防止空指针异常

于 2015-07-06T00:01:24.217 回答
9

获取异常消息(空安全)的最佳方法是:

#[exception.cause.?message or exception.cause]

于 2016-08-31T05:58:41.653 回答
4

你可以这样#[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>

更多细节在这里

于 2014-04-28T14:57:06.623 回答
3

嗨,如果您想使用 MEL 获取异常消息,您也可以(在捕获异常策略中)使用以下表达式。

#[exception.cause.message]
于 2014-10-09T06:40:55.943 回答
1

exception.cause 可以为 null,因此可以这样处理:

#[exception.?cause.message or exception]
于 2017-06-13T06:53:54.317 回答