c# - Using语句遇到未处理异常是否调用IDisposeable?

标签 c# using-statement

如果我有以下内容,IDisposeable 是否仍会在 DisposeableObject 上被调用,或者该对象是否会因为遇到未处理的异常而保持打开状态?

using ( DisposeableObject = new Object() )
{
   throw new Exception("test");
}

最佳答案

using 就像将代码包装在 try...finally 中,然后在 finally 中释放,所以是的,应该调用它。

关于c# - Using语句遇到未处理异常是否调用IDisposeable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4271424/

相关文章:

c# - 使用 Selenium Webdriver C# 关闭弹出对话框

c# - Azure 媒体服务 - 生成新的 AES 加密 token 用于播放

c# - 架构中的服务层 - DLL?

c# - 将变量传递给 SSIS 中的项目参数

c# - Resharper 和 Productivity Power Tools 争夺我的使用权。我怎样才能停止流血?

c# - 将代码作为 "using statement"内的参数传递给函数

c# - 在 VisualStudio 调试器退出时执行代码

c# - 抛出类型为 'System.OutOfMemoryException' 的异常。使用 IDataReader 时的 C#

c# - 哪个更好,什么时候: using statement or calling Dispose() on an IDisposable in C#?

c# - C# 的 using 关键字的范围