This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Problem in Exception Handing

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why the exception in catch block is not shown in the output. Output of the above code is Peace.

 
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gurneeraj,
Its generally not a good practice to return from finally block. It disregards an exception thrown as the case here has been.

Check this-:
return inside finally
[ March 22, 2008: Message edited by: pranav bhatt ]
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey gurneeraj,

Thanks for putting such a nice question , it made me learnt so many new things.

i tried playing with your code , i found the below things:

1)Here strange thing was throwing exception in catch block without declaring it or catching it there only , it tried to take the controll out of catch block , but as we know as soon as catch block finishes , it executes finally in any case and from there you have return statement which made it return to caller with no probs.

2)When i commented your devide by Zero line and removed return statement from fianly it made it to return Error as string from catch block.
It worked like this :As soon as it saw return stat in catch , it jumped to execute finally block , it finished it and then came back to return stat
in catch block.

3)When i just comented devide by zero line and didnt comment return in finaly it made it to return peace and once the control is gone back from finally block , then having return stat in catch doesnt make sense.This was the case in your original question.

I hope it makes your doubt clear.

Ranchers please put some light


Thanks
Vishal
 
    Bookmark Topic Watch Topic
  • New Topic