【问题标题】:"Executed multiple catch exception strategy "“执行多次捕获异常策略”
【发布时间】:2019-09-25 20:00:48
【问题描述】:

我有选择异常策略,我有多个捕获异常策略,我根据错误应用条件。

错误一:

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' (使用密码: YES) (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*")]

这是有效的,但对于获取相同起始字符串的错误。如何区分两者?

【问题讨论】:

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


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-03
      • 2010-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多