在C#中有没有办法捕获任何类型的异常?就像在C++中一样,要捕获任何类型的异常,格式如下
try{
//Statements
}
catch(...){
// Some more statements
}但是c#中的这种格式失败了。帮助?
发布于 2009-11-23 03:17:18
您可以捕获任何内容,如下所示:
catch {}从.NET 2开始,这相当于:
catch(Exception ex) {}因为每个异常(即使是Windows SEH异常)都保证是从System.Exception派生的。
发布于 2009-11-23 03:19:05
查看this链接。这都是关于异常的。
您要做的是使用如下所示的parameter-less catch:
try {
// your code
} catch {
// any exception
}发布于 2009-11-23 03:17:54
try {
// Statements
} catch (Exception ex) {
// Do stuff with ex
}这应该行得通。
https://stackoverflow.com/questions/1779662
复制相似问题