这两段代码之间有什么区别,哪种方法更好.
try
{
using()
{
//Do stuff
}
}
catch
{
//Handle exception
}
using()
{
try
{
//Do stuff
}
catch
{
//Handle exception
}
}
Run Code Online (Sandbox Code Playgroud) using(SomeClass x = new SomeClass("c:/temp/test.txt"))
{
...
}
Run Code Online (Sandbox Code Playgroud)
在使用块内,一切正常,正常处理异常.但是如果构造函数SomeClass可以抛出异常呢?