Can I not catch a specific or custom exception?

后端 未结 6 1676
余生分开走
余生分开走 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 03:05

    First off, it's bad practice to catch Exception unless you log and re-throw it. But if you must, you need to catch your custom exception and re-throw it like so:

    try
    {
    }
    catch (CustomExceptionA custome)
    {
        throw custome;
    }
    catch (Exception e)
    {
        // Do something that hopefully re-throw's e
    }
    

提交回复
热议问题