Is it good to catch a more general type of Exception?

后端 未结 10 1784
無奈伤痛
無奈伤痛 2021-01-06 01:22

If we are to catch specific forms of IOException, or any other kind as a matter of fact, and we only try and catch a couple (and define definitive outputs for t

10条回答
  •  失恋的感觉
    2021-01-06 01:58

    You should not catch these at every possible location where an IOException can happen but further up in the call tree where you are prepared to handle the remaining IOExceptions and the general Exceptions.

    We use the rule of thumb, that you catch specific exceptions at the place where you can handle the error and pass the remaining ones up to the caller.

提交回复
热议问题