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

前端 未结 7 1637
隐瞒了意图╮
隐瞒了意图╮ 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:27

    If you plan on multiple people using your application, having specific exceptions will let you know exactly where your program failed when under the control of someone else. but aside from that, if the program is only for yourself, you can just run it through a debugger, although being in the habit of making very descriptive and unambiguous error handling is a great on to have, if you ever do plan on taking your programming to the masses :)

提交回复
热议问题