try catch
//正常代码
int x=12;
int y=13;
System.out.print("商是"+x/y);
//异常代码
try{
int x=12;
int y=0;
System.out.print("商是"+x/y);
}catch(Exception e){
System.out.print("程序出错");
}finally{
System.out.print("最终执行");
}
System.out.print("后续代码");
执行情况:
情况1:try中没有异常,不执行catch
情况2:try中异常,catch匹配,执行catch,try中异常后续的不执行。
情况3:try中异常,catch不匹配,不执行catch,catch后续的所有的也不执行,try后续的也不执行。但是执行finally后续的。