• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is 5 getting printed here?

 
Jacob Thomas
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Output: 1 4 5

Could anyone please explain why 5 is getting printed here? I thought when an exception occurs, control is transferred to the respective catch clause and then finally gets executed. After this, the program exits. Please correct me if I am wrong. Thanks!
 
Girish Nagaraj
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)When Exception is caught ctrl goes to finally block(if their is any),
and normal execution continues after finally block(as if Exception as not occured).
2)Think! When Exception is caught and handled, What is the necessary to exit.

3)If Exception is not caught then finally block is executed and remaining code after finally block is skipped, -->ctrl goes to calling method.
4)If you do not catch & handle Exception even there -->ctrl goes to its calling method...continues till you catch Exception.
[ May 12, 2006: Message edited by: Girish Nagaraj ]
 
Ashok George
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u r exactly rght girish!!!
 
Krishna Bulusu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when an Exception is caught, the respective exception is executed and the finally block is excecuted and the programme continues from there...untill it reaches the stack....that is why we use Exception mechanism.

plz correct me if i am wrong

regards
krishna.
 
Sreeraj Harilal
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The purpose of try/catch is to handle the error and continue the programme without errors. So u handled the error and programme continues. Simple...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic