When is it OK to catch a RuntimeException

前端 未结 10 1116
眼角桃花
眼角桃花 2020-12-07 11:03

On a recent project I recommended catching a RuntimeException within a test harness code and logging it. The code processes a series of inputs from a database, and I do not

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 11:44

    If a client can reasonably be expected to recover from an exception, make it a checked exception.

    If a client cannot do anything to recover from the exception, make it an unchecked exception.

    Here's the bottom line guideline.

    From Java Docs. Please read this Unchecked Exceptions — The Controversy

提交回复
热议问题