如果无法保证 Final 执行,那么 .NET 4.0 TryCatch Activity 的意义何在?
我今天在设计一个 Activity 时遇到了一个问题,即在 TryCatch 块的 Catch 中重新抛出异常不会执行与其关联的 Final。经过进一步调查,我发现了以下
任何人都可以向我解释一下如果不保证执行,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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您点击该连接页面上的一些链接,您将到达 此页面,您可以在其中找到答案...要点是:
正常的 WF 功能就像
解决方案一样(引用该页面中的 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
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