In the Main method
try {
System.out.println (AA ());
} catch (Exception e) {
TODO auto-generated Catch block
System.out.println ("hehe big");
E.printstacktrace ();
}
System.out.println (4444);
-----------------------------------
static int aa () throws exception{
try {
int a=4/0;
Thread.Sleep (1000);
} catch (Interruptedexception e) {
E.printstacktrace ();
return 1;
}finally{
System.out.println ("finally");
return 2;
}
}
The output results are as follows:
Finally
2
4444
Analysis: Although there is a run exception in try Java.lang.ArithmeticException, but not caught by catch, whether the program is normal operation, or throw an exception, before the first call finally (but one test is to hit the exception first, after the output finally, very surprised), F Inally is used to release resources, if finally use return, this is not the standard notation, this should not be used, finally the return of this method to lose the exception to run, the equivalent of the AA method does not throw an exception
The finally processing effect in exceptions in Java