Contact Us 1-800-596-4880

Error Handler (<error-handler/>)

logo cloud IDE Cloud IDE

logo desktop IDE Desktop IDE

Catches an error thrown by the Mule application and routes it to the first On-Error component configuration that matches the error type.

The Error Handler component has two child elements, On Error Continue and On Error Propagate, which enable you to configure routes that execute when the error raised in the application matches the type of error configured in the handler. Each handler has its own behavior and works relative to the component that contains it (a Flow or a Try scope):

  • On Error Continue (on-error-continue): executes and uses the result of the execution as the result of its container element (as if the container completed the execution successfully). Any transactions at this point commit successfully.

  • On Error Propagate (on-error-propagate): rolls back any transactions, executes, and uses that result to rethrow the existing error. In this case, the container element "fails" its execution.

If there’s no error handling configuration that matches the error, the app follows a default error handling process. See Using Default Error Handling for Messages for more information.

Component XML

This component supports the following XML structure:

<flow name="myFlow">

    <error-handler>
      <on-error-propagate name="onErrorPropagate" >
        <!-- error handling logic -->
      </on-error-propagate>
      <on-error-continue name="onErrorContinue" >
        <!-- error handling logic -->
      </on-error-continue>
    </error-handler>

</flow>

Error Handler (<error-handler/>) attributes are configurable through the UI and XML.

Attribute Name Attribute XML Description

Error handler (default)

doc:name

Editable name for the component to display in the canvas.

N/A

doc:id

Automatically generated identifier for the component.

The <on-error-continue/> and <on-error-propagate/> child elements share the following attributes:

Attribute Name Attribute XML Description

When

when

A matching expression that defines the condition to trigger the execution of this on-error strategy. The expression must evaluate to a Boolean value (true or false).

Type

type

A comma-separated list of Mule error types that defines the errors this on-error strategy handles.

Log exception

logException

Specifies whether to log the error at level ERROR before this strategy handles it. Defaults to true.

Enable notifications

enableNotifications

Specifies if this strategy triggers a notification of type ExceptionNotification when an error occurs. Defaults to true.

Error Handling Example

The following example configures handlers to produce { "MyError": "value was expected to be null" } for a VALIDATION:NOT_NULL error and { "messageANY" : "Some other error" } for other error types.

<error-handler >
  <on-error-continue
    enableNotifications="true"
    logException="true"
    type="VALIDATION:NOT_NULL">
    <ee:transform >
      <ee:message>
        <ee:set-payload>
        <![CDATA[%dw 2.0
        output application/json
        ---
        {
        MyError : error.description as String
        }]]>
        </ee:set-payload>
      </ee:message>
    </ee:transform>
  </on-error-continue>
  <on-error-continue
    enableNotifications="true"
    logException="true"
    type="ANY">
    <ee:transform>
      <ee:message >
        <ee:set-payload >
        <![CDATA[%dw 2.0
        output application/json
        ---
        {
        "messageANY" : "Some other error"
        }
        ]]>
        </ee:set-payload>
      </ee:message>
    </ee:transform>
  </on-error-continue>
</error-handler>