When is it OK to catch a RuntimeException

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

    Personally, I've always been told that you want to catch all RuntimeExceptions; however, you also want to do something about the exception, such as running a failsafe or possibly just informing the user that an error occurred.

    The last Java project that I worked on had a similar approach, at the very least, we would log the exception so that if a user called complaining about a bug, we could find out exactly what happened and see where the error occurred.

    Edit 1: As kdgregory said, catching and ignoring are two different things, generally, people are opposed to the latter :-)

提交回复
热议问题