When is it OK to catch a RuntimeException

前端 未结 10 1114
眼角桃花
眼角桃花 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:43

    You catch RuntimeException for the same reason that you catch any exception: You plan to do something with it. Perhaps you can correct whatever caused the exception. Perhaps you simply want to re-throw with a different exception type.

    Catching and ignoring any exception, however, is extremely bad practice.

提交回复
热议问题