Can I not catch a specific or custom exception?

后端 未结 6 1670
余生分开走
余生分开走 2021-01-18 02:16

I dont want to catch some exception. Can I do it somehow?

Can I say something like this:

catch (Exception e BUT not CustomExceptionA)
{
}
         


        
6条回答
  •  生来不讨喜
    2021-01-18 02:55

    Starting with C# 6, you can use an exception filter:

    try
    {
        // Do work
    }
    catch (Exception e) when (!(e is CustomExceptionA))
    {
        // Catch anything but CustomExceptionA
    }
    

提交回复
热议问题