已經有一個問題發佈here這是非常相似的。我正在更多地擴展這個問題。假設你想捕捉多種類型的異常,但想要以同樣的方式處理它,是否有辦法做類似switch case的事情?try-catch。以相同的方式處理多個異常(或通過下降)
switch (case)
{
case 1:
case 2:
DoSomething();
break;
case 3:
DoSomethingElse()
break;
}
是否有可能以相同的方式處理少數例外。像
try
{
}
catch (CustomException ce)
catch (AnotherCustomException ce)
{
//basically do the same thing for these 2 kinds of exception
LogException();
}
catch (SomeOtherException ex)
{
//Do Something else
}
可能重複[一次捕獲多個異常?](http://stackoverflow.com/questions/136035/catch-multiple-exceptions-at-once) – nawfal 2013-05-18 11:08:32