“执行多次捕获异常策略”

时间:2019-05-08 06:28:33

标签: mule mule-studio anypoint-studio mule-esb

我有选择异常策略,在这里我有多个catch异常策略,我正在根据错误应用条件。

错误1:

  

org.mule.api.MessagingException:列'department_id'不能为空(java.sql.SQLIntegrityConstraintViolationException)。

错误2:

  

org.mule.api.MessagingException:org.mule.module.db.internal.domain.connection.ConnectionCreationException:无法获得URL的连接jdbc:mysql:// localhost:3306 / mulesoft:用户'root1212的访问被拒绝'@'localhost'(使用密码:是)(java.sql.SQLException)(org.mule.module.db.internal.processor.DbConnectionException)。

如何在catch异常策略中使用表达式来区分这两种错误?

第一次捕获-在以下情况下执行:

  

[exception.causeMatches(“ org.mule.api.MessagingException:列'department_id'不能为空*”)]

第二个捕获-在以下情况下执行:

  

[exception.causeMatches(“ org.mule.api.MessagingException:org.mule.module.db.internal.domain.connection.ConnectionCreationException *”)]

使用此方法无法触发捕获异常策略。

  

[exception.causeMatches(“ org.mule.api.MessagingException *”)]

这是有效的,但是对于两个错误都使用相同的起始字符串。我该如何区分两者?

1 个答案:

答案 0 :(得分:1)

如果您要根据根本原因捕获特定的异常。在具有完全限定的异常名称的异常上使用causeBy方法。下面的示例处理2种特定的异常,然后默认捕获所有其他异常。

 <choice-exception-strategy>
      <catch-exception-strategy when="#[exception.causedBy(com.ricston.CustomException)">
        <!-- do stuff -->
      </catch-exception-strategy>
      <catch-exception-strategy when="#[exception.causedBy(org.mule.module.db.internal.domain.connection.ConnectionCreationException)">
        <!-- do stuff -->
      </catch-exception-strategy>
      <catch-exception-strategy>
        <!-- other exceptions. do stuff -->
      </catch-exception-strategy>
    </choice-exception-strategy>
相关问题