如何捕获内部异常? [英] How to catch inner exception?

查看:162
本文介绍了如何捕获内部异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能捕获内部异常:

Is there any possibility to catch inner exception:

try 
{
    ttsbegin;    
    info("step one");        
    try 
    {
       info("step two");
       throw Error("error");
    }
    catch 
    {
       info("catch step two");
    }        
    ttscommit;
}
catch 
{
    info("catch step one");
    ttsabort;
}

我知道我可以在ttsbegin上发表评论;/ttscommit,但我需要进行交易.

I know I can get it commenting ttsbegin; / ttscommit, but I need to have a transaction.

推荐答案

否,不可能 (除非您的例外是UpdateConflictDuplicateKeyException).

No, it is not possible (unless your exception is UpdateConflict or DuplicateKeyException).

文档指出:

如果在事务内引发异常,则该事务将自动中止(发生ttsAbort操作).这既适用于手动引发的异常,也适用于系统引发的异常.

If an exception is thrown inside a transaction, the transaction is automatically aborted (a ttsAbort operation occurs). This applies both for exceptions thrown manually and for exceptions thrown by the system.

当在ttsBegin-ttsCommit事务块内引发异常时,该事务块内没有catch语句可以处理该异常.相反,位于事务块外部的最里面的catch语句是要测试的第一个catch语句.

When an exception is thrown inside a ttsBegin - ttsCommit transaction block, no catch statement inside that transaction block can process the exception. Instead, the innermost catch statements that are outside the transaction block are the first catch statements to be tested.

逻辑是:1)您的事务被抛出中止了2)然后您不可能从事务内部的事务中恢复3)因此将最内层的捕获转移到事务外部.

The logic is: 1) your transaction is aborted by the throw 2) then you cannot possible recover from that inside your transaction 3) hence take the innermost catch outside the transaction.

UpdateConflictDuplicateKeyException这两个例外(双关语是故意的),它们不构成ttsabort,因此可能会在事务中被捕获.

The two exceptions (pun intended) are UpdateConflict and DuplicateKeyException which do not make a ttsabort and hence may be caught inside the transaction.

另请参见此博客条目,该示例演示了那个.

Also see this blog entry which demonstrate that.

使用全部捕获(未指定异常类型)可能会导致问题.请参阅此博客文章.
从D365O更新5开始,如果tts级别大于1,则不会全部捕获这两个异常.参见此博客文章.

Using catch all (no exception type specified) can cause problems. See this blog post.
As of D365O update 5 the the two exceptions are not caught by a catch all if the tts level is greater than one. See this blog post.

这篇关于如何捕获内部异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆