If catching null pointer exception is not a good practice, is catching exception a good one?

后端 未结 6 1716
故里飘歌
故里飘歌 2020-12-03 01:56

I have heard that catching NullPointerException is a bad practice, and i think it is sensibly so. Letting the NullPointerException to propagate to

6条回答
  •  一个人的身影
    2020-12-03 02:33

    You should only catch an Exception if you can add some value by doing so. Otherwise you should let it pass to the caller.

    NullPointerException is usually the result of a bug in your code. How can you sensibly fix this in a catch block?

    Not being bothered about Exceptions is not good practice.

提交回复
热议问题