File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Try catch flow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Try catch flow" Watch "Try catch flow" New topic
Author

Try catch flow

rex tony
Ranch Hand

Joined: Aug 29, 2007
Posts: 159

the answer is
finally
exeception
finshed
Explain the program flow
regards
rex
[ October 10, 2007: Message edited by: Ulf Dittmer ]
PK Ghosh
Greenhorn

Joined: Aug 08, 2006
Posts: 24


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

Joined: Oct 11, 2007
Posts: 83
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

Joined: Sep 27, 2007
Posts: 46
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Try catch flow