Reputation: 5802
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,
Upvotes: 6
Views: 21362
Reputation: 46
exception.cause could be null so it could be handled like this:
#[exception.?cause.message or exception]
Upvotes: 1
Reputation: 12064
Best way to get exception message (null safe) is :
#[exception.cause.?message or exception.cause]
Upvotes: 9
Reputation: 91
In some cases the exception.cause
could be null
, hence advised to use the conditional to display the message:
[(exception.cause!=null)?(exception.cause.message):exception]
This will prevent null pointer exception.
Upvotes: 9
Reputation: 482
Hi if you want to get the exception message using MEL you can also (in a Catch Exception Strategy) use the following expression.
#[exception.cause.message]
Upvotes: 3
Reputation: 4551
You can do #[exception.causedBy]
like
<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
Upvotes: 4