Should unchecked exceptions be caught and dealt with?

后端 未结 6 1531
说谎
说谎 2020-12-17 05:00

I have been reading many posts about exceptions lately and I have a question whether unchecked exceptions should be caught. I have read that if you want your application to

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-17 05:22

    You should catch an exception — checked or unchecked — if you can handle it in a meaningful way to recover from the problem. You generally should not catch an exception if you don't have a good way to handle it.

    I've seen too much code that "handles" exceptions by doing e.printStackTrace() and then continuing as if nothing was wrong. Ignoring a problem like that usually just leads to other problems later.

提交回复
热议问题