Catch multiple exceptions at once?

前端 未结 27 2308
夕颜
夕颜 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:06

    Catch System.Exception and switch on the types

    catch (Exception ex)            
    {                
        if (ex is FormatException || ex is OverflowException)
        {
            WebId = Guid.Empty;
            return;
        }
    
        throw;
    }
    

提交回复
热议问题