JavaSE-13.3.2【Throwable成员方法】
1 package day4.haifei03; 2 3 /* 4 3.4Throwable成员方法 5 6 public String getMessage() 返回此 throwable 的详细消息字符串 7 public String toString() 返回此可抛出的简短描述 8 public void printStackTrace() 把异常的错误信息输出在控制台 9 10 */ 11 public class ExceptionDemo2 { 12 13 public static void main(String[] args) { 14 System.out.println("begin"); 15 method(); 16 System.out.println("end"); 17 } 18 19 public static void method(){ 20 int[] arr = {1, 2, 3}; 21 try{ 22 System.out.println(arr[5]); 23 }catch (ArrayIndexOutOfBoundsException e){ 24 // System.out.println(e.getMessage()); 25 //5 26 27 // System.out.println(e.toString()); 28 //java.lang.ArrayIndexOutOfBoundsException: 5 29 30 //e.printStackTrace(); 31 /* 32 java.lang.ArrayIndexOutOfBoundsException: 5 33 at day4.haifei03.ExceptionDemo2.method(ExceptionDemo2.java:22) 34 at day4.haifei03.ExceptionDemo2.main(ExceptionDemo2.java:15) 35 */ 36 } 37 } 38 39 }