Catch multiple exceptions at once?

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

    catch (Exception ex)
    {
        if (!(
            ex is FormatException ||
            ex is OverflowException))
        {
            throw;
        }
        Console.WriteLine("Hello");
    }
    

提交回复
热议问题