using(SomeClass x = new SomeClass("c:/temp/test.txt"))
{
...
}
在 using block 内,一切正常,异常处理正常。但是,如果 SomeClass
的构造函数可以抛出异常怎么办?
最佳答案
将你的 using 放入 try catch f.e.
try
{
using(SomeClass x = new SomeClass("c:/temp/test.txt"))
{
...
}
}
catch(Exception ex)
{
...
}
关于c# - 捕获在 Using block 的目标对象的构造函数中抛出的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3360860/