常用方法:1、String getMessage();//异常的原因
2、String toSring();//异常的类型及原因
3、void printStackTrace();//异常的类型及原因及位置
public class ExceptionDemo4 {
public static void main(String[] args) {
try {
System.out.println(2/0);
int[] c=new int[4];
System.out.println(c[4]);
} catch (ArithmeticException e) {
System.out.println(e.getMessage());/// by zero
System.out.println(e.toString());//java.lang.ArithmeticException: / by zero
e.printStackTrace();//java.lang.ArithmeticException: / by zero
//at day01.ExceptionDemo4.main(ExceptionDemo4.java:6)
System.out.println("hello");
//与虚拟机不同,已处理可打印hello
}
}
}
网友评论