Mule: receive exception message

I have a default catch exception in Mule, and I'm trying to access the exception message using the Mule expression: # [exception]

This does not work, and I assume that I am trying to access the wrong variable? I am trying to register it with the registrar, and also run a custom component that receives an exception message (as a string.)

Thanks,

+6
source share
5 answers

You can do #[exception.causedBy] as

  <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 here

+5
source

In some cases, exception.cause may be null , so it is recommended that you use a conditional expression to display the message:

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

This will prevent the null pointer from being thrown .

+9
source

The best way to get an exception message (null safe):

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

+8
source

Hi, if you want to receive an exception message using MEL, you can also (in Catch's Exception Strategy) use the following expression.

 #[exception.cause.message] 
+2
source

exception.cause can be null, so it can be handled as follows:

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

All Articles