package dayhou40.day41; public class Abnormal { public static void main(String[] args) { int a=2; int b=0; try { System.out.println(a/b); }catch (Error e){ System.out.println("Error"); }catch (Exception e){ System.out.println("Exception"); }catch (Throwable t){ System.out.println("Throwable"); }finally { System.out.println("最后一定会运行的"); } } }
try是监控区 监控可能发生异常的代码块
catch会逐条去走 直到和监控的异常一样则抛出
**try catch的快速书写 选中要抛出异常的代码块ctrl+Alt+T
try catch可以让程序不停下来 继续往前走