This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Try, Catch & Finalise blocks Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Try, Catch & Finalise blocks" Watch "Try, Catch & Finalise blocks" New topic
Author

Try, Catch & Finalise blocks

Vijayalakshmi Chipada
Greenhorn

Joined: Dec 04, 2000
Posts: 17
Please let me know how this works out:
class Uest{
public static void main (String[]args){
//for (int i=0; i<10; ++i) {
try{
try{
//if (i % 3 == 0) throw new Exception("EO");
System.out.println(i);
}catch (Exception inner) {
i *=2;
if(i % 3 ==0) throw new Exception("E1");
} finally {
++i;
}
}catch (Exception outer) {
i += 3;
}finally {
--i;
}
}
}
}
When I compile I am getting 4 & 5 as answers, Please help me out in this regard.


Ch. Vijayalakshmi
Vijayalakshmi Chipada
Greenhorn

Joined: Dec 04, 2000
Posts: 17
Please help me out in this regard
class Uest{
public static void main (String[]args){
//for (int i=0; i<10; ++i) {
try{
try{
//if (i % 3 == 0) throw new Exception("EO");
System.out.println(i);
}catch (Exception inner) {
i *=2;
if(i % 3 ==0) throw new Exception("E1");
} finally {
++i;
}
}catch (Exception outer) {
i += 3;
}finally {
--i;
}
}
}
}
When compilation I am getting 4 & 5 as answers
Yamuna Pattathil
Greenhorn

Joined: Dec 03, 2000
Posts: 19
I have the same code with a lot of sop statements. You can easily understand the program flow.
The one with label "original" is the only one you had in your code.

Also note that 0, 3, 6, 9 etc are values of i(<10) which causes if condition to be executed and hence Exception.
[This message has been edited by Yamuna Pattathil (edited December 04, 2000).]
saumil shukla
Ranch Hand

Joined: Dec 01, 2000
Posts: 47
is there any way to trace this?
Yamuna Pattathil
Greenhorn

Joined: Dec 03, 2000
Posts: 19
I have given the output and explanations below


Hope this helps.
[This message has been edited by Yamuna Pattathil (edited December 04, 2000).]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Try, Catch & Finalise blocks
 
Similar Threads
nested try catch finally in a for loop : how does it work
Loop with throw ...
try/catch
try/catch
try catch finally