C#功能请求:最终块不会掩盖原始异常. [英] C# Feature Request: Finally block that doesn't mask the original exception.

查看:64
本文介绍了C#功能请求:最终块不会掩盖原始异常.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我希望原始异常升级而不是finally块中的清理代码时,我写了很多这样的代码.

I write a lot of code like this when I want the original exception to escalate and not my cleanup code in the finally block.

尝试
{
    //可能会崩溃
}
终于
{
   试试
    {
       //清理
    }
    catch(异常例外)
    {      
      //log但忽略,因此第一个异常升级
    }
}

try
{
    //may crash
}
finally
{
    try
    {
        //cleanup
    }
    catch (Exception ex)
    {       
       //log but ignore so the first exception escalates
    }
}

我知道由于现有的逻辑用法而改变了finally块的行为为时已晚,但是拥有另一个仅升级原始异常而不是清除代码异常的块将是很好的选择.另外,它让我不寒而栗 赶上Exception.我不知道该怎么称呼这个新块,也许是最终尝试".

I know it's too late to change the behavior of the finally block due to existing logical usage but it would be nice to have another block that just escalates the original exception and not the cleanup code exception. Plus, it gives me the shivers to write a catch on Exception. I don't know what to call this new block though, 'finally-try' maybe.

推荐答案

Tomasz

Hi Tomasz,

您的描述不清楚,p 向我扑朔迷离.您能给我一个详细的吗?

Your description is unclear and puzzles me. Can you please give me a detailed one?

最感谢,


这篇关于C#功能请求:最终块不会掩盖原始异常.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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