Nav

Migrating Exception Strategies to Mule Error Handlers

The following examples will guide you through the migration of the different exception strategies of Mule 3 considering the new error handling components in Mule 4.

Catch Exception Strategy

A Catch Exception Strategy is equivalent to an Error Handler with a single on-error-continue component that accepts all errors, which is the default configuration:

Mule 3 Example

        
     
1
2
3
4
5
6
<flow name="catch">
  <!-- flow logic -->
  <catch-exception-strategy>
    <!-- error handling logic -->
  </catch-exception-strategy>
</flow>
Mule 4 Example

        
     
1
2
3
4
5
6
7
8
<flow name="catch">
  <!-- flow logic -->
  <error-handler>
    <on-error-continue>
      <!-- error handling logic -->
    </on-error-continue>
  </error-handler>
</flow>

Rollback Exception Strategy

A simple (no redelivery) rollback exception strategy is equivalent to an error handler with a single on-error-propagate component that accepts all errors, which is the default configuration:

Mule 3 Example

        
     
1
2
3
4
5
6
<flow name="rollback">
  <!-- flow logic -->
  <rollback-exception-strategy>
    <!-- error handling logic -->
  </rollback-exception-strategy>
</flow>
Mule 4 Example

        
     
1
2
3
4
5
6
7
8
<flow name="rollback">
  <!-- flow logic -->
  <error-handler>
    <on-error-propagate>
      <!-- error handling logic -->
    </on-error-propagate>
  </error-handler>
</flow>

With Redelivery

  • idempotent-redelivery-policy gets renamed to redelivery-policy

  • org.mule.runtime.core.api.exception.MessageRedeliveredException has been moved to org.mule.runtime.core.exception.MessageRedeliveredException

  • maxRedelivery in rollback-exception-strategy is not supported anymore. A <redelivery-policy> element with maxRedelivery must be created inside the message-source.

Choice Exception Strategy

A Choice exception strategy with inner catch/rollback exception strategies is equivalent to an error handler with on-error components continue/propagate according to the exception strategy kind, as explained above:

Mule 3 Example

         
      
1
2
3
4
5
6
7
8
9
<flow name="choice">
  <!-- flow logic -->
  <choice-exception-strategy>
      <rollback-exception-strategy when="#[exception.causedBy(java.lang.IllegalStateException)]">
          <!-- error handling logic -->
      </rollback-exception-strategy>
      <catch-exception-strategy/>
    </choice-exception-strategy>
</flow>
Mule 4 Example

         
      
1
2
3
4
5
6
7
8
9
<flow name="choice">
  <!-- flow logic -->
  <error-handler>
    <on-error-propagate when="#[exception.causedBy(java.lang.IllegalStateException)]">
      <!-- error handling logic -->
    </on-error-propagate>
    <on-error-continue/>
  </error-handler>
</flow>

Reference Exception Strategy

Considering that the referenced exception strategy has already been migrated according to the above guidelines, migrating the actual reference is just adding a reference error-handler.

Mule 3 Example

         
      
1
2
3
4
<flow name="reference">
  <!-- flow logic -->
  <exception-strategy ref="referencedHandler"/>
</flow>
Mule 4 Example

         
      
1
2
3
4
<flow name="reference">
  <!-- flow logic -->
  <error-handler ref="referencedHandler"/>
</flow>