【发布时间】:2011-01-18 11:35:33
【问题描述】:
已经发布了一个问题here 非常相似。我的进一步扩展了这个问题。假设您想捕获多种类型的异常但想以相同的方式处理它,有没有办法做类似 switch case 的事情?
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
}
【问题讨论】:
标签: c# exception exception-handling error-handling