在程序当中,只要有一个地方发生异常,下面的所有代码都不会执行。
int a = 1/0;
int b = 1+3;
System.out.println(a);
System.out.println(b);
发生异常时,首先先看自己代码。
Shift+Alt+z +y 异常处理快捷键
input.hasNextInt
try里面声明,一般都是放在try外面。
Systrm.exit(1); 不会执行finally里的代码
catch是处理异常
public void print( )throw Exception{ } 抛出异常
throws 申明异常 throw 抛出异常 try 执行可能产生的异常代码 catch 捕获异常
int a = 1/0;
int b = 1+3;
System.out.println(a);
System.out.println(b);
发生异常时,首先先看自己代码。
Shift+Alt+z +y 异常处理快捷键
input.hasNextInt
try里面声明,一般都是放在try外面。
Systrm.exit(1); 不会执行finally里的代码
catch是处理异常
public void print( )throw Exception{ } 抛出异常
throws 申明异常 throw 抛出异常 try 执行可能产生的异常代码 catch 捕获异常