Java - where and how should exceptions be used?

前端 未结 9 1428
天涯浪人
天涯浪人 2021-01-02 05:03

I was reading some things about exception handling in Java, to be able to write better code. OK, I admit, I am guilty; I\'ve used too much try-catch{} blocks, I\'ve used

9条回答
  •  迷失自我
    2021-01-02 05:31

    Please, do not return null in case of non-fatal errors. Return a NullObject instead.

    Otherwise you need a null check after each and every call to your code which is a pain, and if forgotten will cause the code to crash.

提交回复
热议问题