异常处理

JLo*_*pez 1 c# exception

C#中有没有办法捕获任何异常?就像在C++中捕获任何类型的异常一样,格式就像

try{
//Statements
}
catch(...){
// Some more statements
}
Run Code Online (Sandbox Code Playgroud)

但是c#中的这种格式失败了.救命?

And*_*mar 7

你可以抓住任何东西:

catch {}
Run Code Online (Sandbox Code Playgroud)

从.NET 2开始,这相当于:

catch(Exception ex) {}
Run Code Online (Sandbox Code Playgroud)

因为保证每个异常(甚至是Windows SEH异常)都是从中派生出来的System.Exception.