Catch multiple exceptions at once?

前端 未结 27 1836
夕颜
夕颜 2020-11-22 11:31

It is discouraged to simply catch System.Exception. Instead, only the "known" exceptions should be caught.

Now, this sometimes leads to unnecce

27条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 12:09

    Note that I did find one way to do it, but this looks more like material for The Daily WTF:

    catch (Exception ex)
    {
        switch (ex.GetType().Name)
        {
            case "System.FormatException":
            case "System.OverflowException":
                WebId = Guid.Empty;
                break;
            default:
                throw;
        }
    }
    

提交回复
热议问题