Should unchecked exceptions be caught and dealt with?

后端 未结 6 1541
说谎
说谎 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:21

    Nothing forbids you from catching runtime exceptions.

    The trend, nowadays, is to use more and more runtime exceptions, and less and less checked exceptions. Spring, Hibernate, and the latest Java EE specs use runtime exceptions almost exclusively. This makes the business code easier to read and less cumbersome.

    The runtime exceptions are generally intended to be not caught at all, or only caught at the bottom of the call stack, in the UI layer, in order to display an error message, because that's usually the only thing you can do when such an exception occurs.

提交回复
热议问题