This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception flow control Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception flow control" Watch "Exception flow control" New topic
Author

Exception flow control

Kedar Dravid
Ranch Hand

Joined: May 28, 2004
Posts: 333
Consider the code below:



O/p: 5
8
I Can't quite figure out how the o/p is
5
8
Could anybody guide me on the flow control in this one?
[ March 07, 2005: Message edited by: Mark Spritzler ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

First let's put that code inside the CODE tags so that we can read it.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

OK we start with 0

the first if throws an Exception, and it goes to the outer catch, which adds three, making the value 3, the finally is then run to make it 4, and the incrementer of the loop makes it 5.

So now we run the loop for the number 5. It gets passed the two ifs and prints out 5. ANSWER PART I

It then runs the inner Finally, making it 6, then runs the outer finally making it 7, and then the loop incrementor makes it 8.

So now we run the loop for the number 8. It gets passed the two ifs and prints out 8. ANSWER PART II

So the inner finally makes it 9, the outer finally makes it 10, and the incrementer of the loop makes it 11, and therefore does not continue the loop and ends execution.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception flow control
 
Similar Threads
try/catch
Jammi Question
About Exception Handling.....
Exception HAndling
try/catch