Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Finally

 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,
Here i have some confusion about sequence of output. is it not supposed to first handle the Exception thrown in catch block then execute finally block??
please explain it to me.


Output:
CaughtMalformedURLException
End finally
Exception at main()
regards
vivek

[This message has been edited by Vivek Shrivastava (edited August 08, 2000).]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vivek
The reason why you get the following is as follows.
Once the code a==null is successfull, the MalformedURLException is thrown. This exception is caught in the same test() method which prints CaughtMalformedURLException and again throws the same execption.
But before control is transferred to the main, finally() is executed, so it prints
End finally.
Then this exception is caught in the main() method which prints
Exception at main().
Hope this clarifies
Anand
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear vivek,
note that MalformedURLexception is a checked exception.
1. this means that this exception must either be caught using the try-catch construct, or , be declared in the throws clause of the invoking method.
2. in your code, this exception is caught using the first catch construct. it is then RETHROWN.
3. since it is checked exception, it has to be declared in the throws clause of invoking method ie test(). note that this is not done. the test() method only throws one IOException.
3. thus, after execution of finally, method is aborted and hence result
hth, chetan
 
A tiny monkey bit me and I got tiny ads:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic