如果无法保证 Final 执行,那么 .NET 4.0 TryCatch Activity 的意义何在?

发布于 2024-09-10 06:14:53 字数 464 浏览 2 评论 0原文

我今天在设计一个 Activity 时遇到了一个问题,即在 TryCatch 块的 Catch 中重新抛出异常不会执行与其关联的 Final。经过进一步调查,我发现了以下

http://connect.microsoft.com/wf/feedback/details/557601/try-catch-activity-never-executes-finally-if-exception-propagates

任何人都可以向我解释一下如果不保证执行,finally 块在此活动中有何用处?

我能看到的唯一情况是您是否嵌套了 try 块。

I was designing an Activity today and I came across an issue by which rethrowing an exception within the Catch of a TryCatch block does not execute the Finally which is also associated with it. Upon further investigation I came across the following

http://connect.microsoft.com/wf/feedback/details/557601/try-catch-activity-never-executes-finally-if-exception-propagates

Can anyone explain to me what the use of the finally block is in this activity if it is not guaranteed to execute?

The only case I can see is if you have nested try blocks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甲如呢乙后呢 2024-09-17 06:14:53

如果您点击该连接页面上的一些链接,您将到达 此页面,您可以在其中找到答案...要点是:

正常的 WF 功能就像

try
{
    Environment.FailFast("Game Over.");
}
finally
{
    Console.WriteLine("Not Called");
}

解决方案一样(引用该页面中的 steve danielson):
如果您将“取消”指定为转义工作流根的未处理异常的行为,那么它应该提供所需的行为。我已经传递了此反馈,并将确保更新文档以反映这一点。

Workflowapplication.OnUnhandledException = UnhandledExceptionAction.Cancel

HTH

if you follow some links from that connect page you will reach this page where you may find an answer... the gist is:

The normal WF functions like

try
{
    Environment.FailFast("Game Over.");
}
finally
{
    Console.WriteLine("Not Called");
}

the solution is (quoting steve danielson from that page):
If you specify Cancel as the behavior for unhandled exceptions escaping the root of the workflow then it should give the desired behavior. I have passed this feedback along and will ensure that the documentation is updated to reflect this.

ie Workflowapplication.OnUnhandledException = UnhandledExceptionAction.Cancel

HTH

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文