我想知道是否能够安全地编写一个只捕获所有System.Exception类型的catch()。还是说我必须坚持使用catch(Exception)来完成这个任务。我知道对于其他异常类型(例如InvalidCastException),我必须指定类型,如catch(InvalidCastException)。换句话说,我想问以下代码示例是否相同。
可以这样写:
catch (Exception e) { // catch all System.Exception types }
也可以这样写:
catch () { // catch all System.Exception types }
两者都是一样的。
这...
可以这样写:
catch (Exception e) { // catch all System.Exception types }
也可以这样写:
catch () { // catch all System.Exception types }
两者都是一样的。
try
{
//do something
}
catch(Exception)
{
//handle exception
}
这段代码意味着在HTML文档中有一个段落元素。段落元素通常用于显示一段文本,浏览器会在文本的前后添加空白以分隔段落。
try
{
//do something
}
catch() //Causes compile time error "A class type expected"
{
//handle exception
}
并且这个...
try
{
//do something
}
catch
{
//handle exception
}
更新:我的问题有误。catch()
在c#中是不允许的。
catch(Exception)
或catch(NullReferenceException)
(如果你知道异常)。在C#.net中,你不能让catch块为空,像这样catch(),Intellisense会显示错误。 - Shankar Narayana Damodaran