• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Try catch flow

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic