例子:
--異常捕獲級别
throw用在方法中 throwd在方法上抛出異常
package oop.exception; public class Demo1 { public static void main(String[] args) { int a=1; int b=0; //ctrl+alt+t 異常快捷鍵 //捕獲異常 try { System.out.println(a / b); } catch (Error e) { System.out.println("Error"); //列印異常 e.printStackTrace(); } catch (Exception e) { System.out.println("Exception"); } catch (Throwable e) { System.out.println("Throwable"); } finally { System.out.println("finally"); } //test方法中的捕獲異常 try { test(1,0); } catch (ArithmeticException e) { System.out.println("asdasfasfasfas"); } finally { System.out.println("finally"); } } public static void test(int a,int b) throws ArithmeticException { if (b==0) { System.out.println("asd"); throw new ArithmeticException(); } } }