异常捕获

lea*_*ing 1 c# exception-handling

有什么区别

 try
 {
     ... 
 }
 catch (NHibernate.ADOException exception)
 {}
Run Code Online (Sandbox Code Playgroud)

try
{
    ... 
}
catch (exception ex)
{}
Run Code Online (Sandbox Code Playgroud)

Grz*_*nio 6

在catch块中,您可以指定要捕获的异常.所以,如果你有

try {}
catch(Exception e){}
Run Code Online (Sandbox Code Playgroud)

它将捕获从Exception类派生的所有异常(因此所有异常).如果你有:

try{}
catch (NHibernate.ADOException exception){}
Run Code Online (Sandbox Code Playgroud)

它只会捕获ADOException或从ADOException派生的异常.因此,如果你得到一个ArgumentException,它将传递,好像没有try/catch.