try catch finally
class Test{
public static void main(String args []){
System.out.println(1);
//try catch finally
try{
System.out.println(2);
int i = 1/0 ; //有可能出现异常的代码 如果产生了异常,就进入catch
System.out.println(3);
}
catch(Exception e){
System.out.println(4);
e.printStackTrace();
System.out.println(5);
}
finally{
System.out.println("无论出不出异常,都走finally,即异常的出口")
}
System.out.println(6);
}
}
/*
1.如果没有异常,就走try
2.如果有异常,就走catch
3.无论有没有异常,都走finally
*/