Try-catch: is this acceptable practice?

前端 未结 8 2130
终归单人心
终归单人心 2020-12-17 17:35

We have received Java code from a software supplier. It contains a lot of try-catch blocks with nothing in the catch part. They\'re all over the pl

8条回答
  •  独厮守ぢ
    2020-12-17 18:11

    It's not the best:

    • It hides evidence of the exception so debugging is harder

    • It may cause features to fail silently

    • It suggests that the author might actually have wanted to handle the exception but never got around to it

    So, there may be cases where this is OK, such as an exception that really is of no consequence (the case that comes to mind is Python's mkdirs, which throws an exception if the directory already exists), but usually, it's not so great.

提交回复
热议问题