Will catching an exception catch a parent class of that exception

后端 未结 3 520
隐瞒了意图╮
隐瞒了意图╮ 2021-01-14 12:40

In Java I have a method catching an exception \'ChildException\' that extends \'NewException\'. If that method calls another method that throws a \'NewException\' and let\'s

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-14 13:26

    It will only catch the Exception you specify or it's subclass. Just write it so it catches the parent Exception and you're safe.

提交回复
热议问题