2019-01-16 13:45:00 397浏览
今天扣丁学堂Java培训老师给大家介绍一下关于Java异常处理与throws关键字用法分析详解,首先在Java异常处理的时候,我们先来认识一下异常和一些案例!
Exc e=null; System.out.println(e.i);
int a=10; int b=0; System.out.println(a/b);
try{ 异常语句; } catch(Exception e){ } finally{ 一定会执行的代码; }
int a=10; int b=0; try { System.out.println(a/b); } catch (ArithmeticException e){ System.out.println(e); }
int temp=0; Exc e=null; try { temp=e.a/e.b; System.out.println(temp); } catch (NullPointerException e1){ System.out.println("空指针异常"+e1); } catch (ArithmeticException e1){ System.out.println("算数异常"+e1); } finally { System.out.println("程序退出"); }
public void tell()throws Exception{}
public static void main(String [] args){ try { tell(10,0); } catch (Exception e){ System.out.println(e); } } public static void tell(int i,int j)throws ArithmeticException{ int temp=0; temp=i/j; System.out.println(temp); }
public static void main(String [] args)throws Exception{ tell(10,0); } public static void tell(int i,int j)throws ArithmeticException{ int temp=0; temp=i/j; System.out.println(temp); }
此时,最后抛给JVM进行处理,以上就是关于扣丁学堂Java培训之异常处理与throws关键字用法分析的详细介绍,希望对大家的学习有所帮助,请关注扣丁学堂Java培训官网、微信等平台,扣丁学堂IT职业在线学习教育平台不仅为您提供权威的Java视频教程供大家学习,还精心的准备了Java从入门到精通开发实战技能,定能让你学有所成。扣丁学堂Java技术交流群:670348138。
【关注微信公众号获取更多学习资料】