DESKTOP-EA11HIB_20200904-蒋宇飞
一、问题
public static void main(String[] args) {
try {
int a = 100 / 0 ;//java.lang.ArithmeticException
System.out.println( a );
} catch ( NullPointerException npe ) {
System.out.println( "NullPointerException : " + npe );
} catch ( ArithmeticException ae ) {
System.out.println( "ArithmeticException : " + ae );
} catch ( Exception e ) {
System.out.println( "Exception : " + e );
} catch ( Throwable t ) {
System.out.println( "Throwable : " + t );
}
}
Throwable 类是 Exception 类的父类,Exception 类是 ArithmeticException 类和 NullPointerException 类的父类,子类在前,父类在后程序可以编译,但父类在前,子类在后却显示受检查异常。
二、感想
坚持。
近期评论