public class Test { String x; public static void main(String[] args) { Test test = new Test(); try { System.out.println(5/0); } catch (ArrayIndexOutOfBoundsException e) { test.x = "hello world"; System.out.println(test.x.length()); } catch (NullPointerException e) { // TODO: handle exception test.x = "hello world"; System.out.println(test.x.length()); } catch (Exception e) { // 必须放到最后 // TODO: handle exception e.printStackTrace(); }finally { System.out.println("finally"); } System.out.println("end"); } }
java.lang.ArithmeticException: / by zero at com.demo.pkg5.Test.main(Test.java:10) finally end
时间: 2024-10-26 20:44:14