2016-04-11 1 views

Répondre

1

fami s un,

try 
{ 
    doSomething() 
} 
catch (AmbiguousMatchException) 
{ 
    doSomethingElse() 
} 
2

Si vous ne comptez pas utiliser les détails d'exception, vous pouvez utiliser l'essayer comme ceci:

try 
{ 
    doSomething(); 
} 
catch // all types of exceptions will caught here 
// if you need to deal with particular type of exceptions then specify them like 
// catch (AmbiguousMatchException) 
{ 
    doSomethingElse(); 
} 

Ou bien vous devez utiliser la variable pour quelque chose comme ce qui suit:

try 
{ 
    doSomething(); 
} 
catch (AmbiguousMatchException MyException) 
{ 
    WriteToLog(MyException.ToString()); 
    // doSomethingElse(); 
} 

où la méthode WriteToLog sera définie comme comme ce qui suit:

public static void WriteToLog(string exceptionDetails) { 
    // write the details to a file/DB 
}