请看下面的代码行:
public void methodBla(){
try{
system.out.println(2/0);
{
catch(MyArithmeticException me){
system.out.println("Error: My exception");
}
catch(Exception a){
system.out.println("Error: general exception");
}
}
我不明白为什么,当我试图用我的自定义类捕获 ArithmeticException 时:我的ArithmeticException 扩展了 ArithmeticException。
Public class MyArithmeticException extends ArithmeticException{
public MyArithmeticException(String str){
super("My Exception " + str);
}
}
MyArithmeticException 没有捕捉到它,它只捕捉到第二个“catch”(catch(Exception a))。
谢谢Z