gpt4 book ai didi

exception - ule子-未针对特定异常调用捕获异常策略

转载 作者:行者123 更新时间:2023-12-03 07:54:48 25 4
gpt4 key购买 nike

我正在尝试为将数据写入数据库的Mule应用程序实现错误处理策略。我有以下尝试插入具有重复标识符的记录时引发的异常示例:

ERROR 2014-03-17 16:02:15,990 [[processes].inputConnector.receiver.01] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message : Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=jdbc://insertRecord, connector=JdbcConnector
{
name=dbQueries
lifecycle=start
this=4c6f44a0
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=false
connected=true
supportedProtocols=[jdbc]
serviceOverrides=<none>
}
, name='endpoint.jdbc.insertRecord', mep=ONE_WAY, properties={queryTimeout=-1}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: HashMap
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140317160209540' defined on 'TESTTABLE'. (org.apache.derby.iapi.error.StandardException)
org.apache.derby.iapi.error.StandardException:-1 (null)
2. The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140317160209540' defined on 'TESTTABLE'.(SQL Code: 30000, SQL State: + 23505) (org.apache.derby.impl.jdbc.EmbedSQLException)
org.apache.derby.impl.jdbc.SQLExceptionFactory:-1 (null)
3. The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140317160209540' defined on 'TESTTABLE'.(SQL Code: 30000, SQL State: + 23505) (java.sql.SQLIntegrityConstraintViolationException)
org.apache.derby.impl.jdbc.SQLExceptionFactory40:-1 (null)
4. The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140317160209540' defined on 'TESTTABLE'. Query: INSERT INTO TestTable (Id, Quantity) VALUES (?, ?) Parameters: [261000153085, 7](SQL Code: 30000, SQL State: + 23505) (java.sql.SQLException)
org.apache.commons.dbutils.QueryRunner:540 (null)
5. Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=jdbc://insertRecord, connector=JdbcConnector
{
name=dbQueries
lifecycle=start
this=4c6f44a0
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=false
connected=true
supportedProtocols=[jdbc]
serviceOverrides=<none>
}
, name='endpoint.jdbc.insertRecord', mep=ONE_WAY, properties={queryTimeout=-1}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: HashMap (org.mule.api.transport.DispatchException)
org.mule.transport.AbstractMessageDispatcher:109 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
ERROR 23505: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140317160209540' defined on 'TESTTABLE'.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.execute.IndexChanger.insertAndCheckDups(Unknown Source)
at org.apache.derby.impl.sql.execute.IndexChanger.doInsert(Unknown Source)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

我已经定义了选择异常策略来处理不同的异常,并使用以下方法来处理所概述的情况:
<catch-exception-strategy when="#[exception.causeMatches(org.apache.derby.*)]" doc:name="Catch Exception Strategy">         
<logger level="ERROR" message="Database error." doc:name="Logger"/>
</catch-exception-strategy>

但是,异常总是路由到默认策略,而不是上面定义的catch策略。我假设这是我的“何时”表达的问题,但我不确定如何解决它。任何帮助,将不胜感激。谢谢

最佳答案

这是一种以正则表达式为参数的方法。
尝试以下一项,它应该可以工作。

<catch-exception-strategy when="#[exception.causeMatches('org.?apache.?derby.?.*')]" doc:name="Catch Exception Strategy">         
<logger level="ERROR" message="Database error." doc:name="Logger"/>
</catch-exception-strategy>
希望这可以帮助。

关于exception - ule子-未针对特定异常调用捕获异常策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22460597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com