Empty catch blocks

后端 未结 5 2042
春和景丽
春和景丽 2020-12-08 19:57

I sometimes run into situations where I need to catch an exception if it\'s ever thrown but never do anything with it. In other words, an exception could occur but it doesn\

5条回答
  •  抹茶落季
    2020-12-08 20:07

    Using an empty catch block just swallows the Exception, I would always handle it, even if it is reporting back to you that an Exception occurred.

    Also catching the generic Exception is bad practice due to the fact it can hide bugs in your application. For example, you may have caught an ArgumentOutOfRange exception which you did not realize was happening and then swallowed it (I.e. not done anything with it).

提交回复
热议问题