Access Keys:
Skip to content (Access Key - 0)
Cancel    
Cancel   
 

Contents

Choice exception strategy documentation

Choice exception strategy allows to define different execution paths based on content type at the type of the exception. Message routing is done using mule expressions. Each exception strategy configured in <route-exception-strategy> allows an expression attribute. Exception strategy to be executed will be pick by evaluating each exception strategy expression. The first one that evaluates to true will be executed. In case that none of them evaluates to true the default exception strategy configured will be used.

Example use case
You have to process product orders that are stored as files in an external server. Each order must be converted to an Order object which can be later processed by a component. If the component throws a org.mule.example.ValidationException, or any other subtype, then the order is invalid and should send to a vm endpoint holding invalid orders. If the component throws an instance of org.mule.example.AlreadyProcessedException then the order can be discarded. But for any other case the inbound message should not be consumed so it can be reprocessed later.

  • In case that a org.mule.example.AlreadyProcessedException exception is thrown then first exception strategy is executed
  • In case that a org.mule.example.ValidationException exception is thrown then the second exception strategy is executed
  • In any other case rollback-exception-strategy will be executed. Only the last exception strategy configured inside choice-exception-strategy can have an empty expression. Empty expression means that every message is accepted

Usefull expressions for exception checking

  • exception.causeBy(ExceptionType): Checks that the exception is an instance of ExceptionType
  • exception.causeExactlyBy(ExceptionType): Checks that the exception is only of type ExceptionType
  • exception.causeMatches(Regex): Checks that the exception type name matches regular expression Regex

Additional considerations

  • If none of the configured exception strategies expression attribute evaluates to true, then the default exception strategy configured for the application will be executed.
  • Any mule expression evaluator can be use in the expression attribute
  • In case you need to do routing base on exception type consider using exception-type expression evaluator