一次捕获多个异常?
问题: It is discouraged to simply catch System.Exception . 不建议仅捕获 System.Exception 。 Instead, only the "known" exceptions should be caught. 相反,仅应捕获“已知”异常。 Now, this sometimes leads to unneccessary repetitive code, for example: 现在,这有时会导致不必要的重复代码,例如: try { WebId = new Guid(queryString["web"]); } catch (FormatException) { WebId = Guid.Empty; } catch (OverflowException) { WebId = Guid.Empty; } I wonder: Is there a way to catch both exceptions and only call the WebId = Guid.Empty call once? 我想知道:有没有一种方法可以捕获两个异常,并且只调用一次 WebId = Guid.Empty ? The given example is rather simple, as it's only a GUID .