| Author |
Return from catch block
|
rajaraman navaneethan
Ranch Hand
Joined: Feb 26, 2005
Posts: 86
|
|
Hi Friends, Can anyone please tell me if there is a return statement from the catch block, and there is a finally block, is the value from the catch block returned first. I am little confused as how the code flows in the following program. public class Test1 { static int i=0; public static void main(String[] args) { System.out.println(meth1()); System.out.println(i); } static int meth1() { try { if(i==0) { throw new Exception(); } } catch(Exception e) { System.out.println(i); return ++i; } finally { System.out.println(i); return ++i; } } } The output is 0 1 2 2. regards, Raja
|
 |
Srikanth Ramu
Ranch Hand
Joined: Feb 20, 2007
Posts: 76
|
|
|
The i value is first incremented in catch block and then in finally block. BTW why do you want to increment the value in catch and finally instead you could do it after finally block
|
 |
 |
|
|
subject: Return from catch block
|
|
|