• 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Problem in Exception Handing  RSS feed

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
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

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!