In Java, what is the difference between catch a generic exception and a specific exception (eg. IOException?)

前端 未结 7 1645
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 14:39

Currently I\'m catching only generic exceptions, but i want change this to catch the specific exceptions, but what is the advantage of this?

7条回答
  •  隐瞒了意图╮
    2020-12-03 15:25

    If you have a block of code which can throw different exceptions, and you surround that with a general try {} catch {Exception e}, you won't know what exactly happened and how you should handle the error.

提交回复
热议问题