Hi, public class test{ static string s=""; public static void metod(int i){ try{ if(i==2){throw new Exception(); } s+=1; } catch (Exception e) { s+=2; return;} finally { s+=3; } s+=4; } public static void main (String args[]) { method(1); method(2); Sytem.out.println(s); } prints 13423 but i feel it should be 134234 since the exception is caught the line after finally should be executed. Please could someone help me on this Regards Neha
nss
Fei Ng
Ranch Hand
Joined: Aug 26, 2000
Posts: 1241
posted
0
If there is no return in catch(){.... return;} you are right. But there is a return statment. Before the return; in catch(){} the final {} gets to run and then back to the return statement. I think you know this already, just make sure you read all the code.
[This message has been edited by FEI NG (edited December 02, 2001).]
Sonali Joshi
Greenhorn
Joined: Dec 01, 2001
Posts: 8
posted
0
Thanx FEING I was not aware of this. Now that my exam date is coming near i am getting all the more confused. Thnk you once again Regards Neha
sj
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
How come the same guy has two different names ?? Neha Sawant and Sonali Joshi, which one really exists? ------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform