Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Try catch flow

 
rex tony
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the answer is
finally
exeception
finshed
Explain the program flow
regards
rex
[ October 10, 2007: Message edited by: Ulf Dittmer ]
 
PK Ghosh
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Here: first aMethod is calling then its throwing exception which is ultimately caught by finally block and printing "finally" now controll comes back to main try block which found that calling (aMethod()) has thrown exception so it caught and print "exception" and last statement as usual print.
 
Oggi Olli
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition, finally is where code goes that must be done no matter what happens.
It is a guarantee.
Since there is no catch block, finally must do whatever it is supposed
to before the method ends. When finally completes the method throws the
exception back to main which in turn catches it.
[ October 11, 2007: Message edited by: Steinar Steinnes ]
 
Craig Bayley
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not nitpicking but finally doesn't catch anything at all. It simply is gauranteed to execute regardless of whether an exception was thrown or not.

Flow is:
aMethod is called, and throws an exception. This exception is not caught in the aMethod.
finally is executed, as it is guaranteed to before the exception is thrown on.
"finally"
The main method catches the exception in its catch block, and deals with it.
"exception"
The main method continues processing until it has completed.
"finished"
[ October 11, 2007: Message edited by: Craig Bayley ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic