Search code examples
javamulemule-studiomule-el

Mule: getting a hold of the exception message


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,


Solution

  • 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