Is it OK to try/catch something just to check if an exception was thrown or not?

前端 未结 10 641
Happy的楠姐
Happy的楠姐 2020-12-28 13:09

Is it a good way to try something useless just to see if a particular exception is thrown by this code ?
I want to do something when the exception is thrown, and nothing

10条回答
  •  一整个雨季
    2020-12-28 13:28

    A comment on kriss' answer: I don't see a "superb memory leak" here. There is no reference to the created BigDecimal. As soon as this method completes, and we go out of scope, the object is eligible for garbage collection.

    Memory leaks occur when we hold references we no longer need so the object can't be garbage collected.

提交回复
热议问题