This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

exceptions????  RSS feed

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if a try-catch-finally statement does not have a catch clause to handle an exception that is thrown within the body of the try statement?

isnt it that it will throw uncaughtexception?
thanks...

raymond
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it will bubble up to next context level looking for that exception or any of its super exception. If it can not find any all the way upto main(), it will terminate and throw that exception.
Any body correct if I am wrong.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think that you will get a compiler error if ther is no catch for a try. It doesn't matter if theres no finally block, although is always good practiceto have one, just that the compilier won;t complain.
An uncaught exception is when none of the catch blocks match the exception thrown, then the finally block is executed and the exception is passed up to the next level.
Incedentally if the exception is caught, the finally block executes and any other code after the finally block upto the end brace of the method.
I think this is correct , I a newbie to all this my self.
regards
satpal
[ October 02, 2002: Message edited by: Satpal Chander ]
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have a try that has no "catch", only a "finally".
If you neither catch a checked exception nor declare it in your method's throws clause, the compiler will complain.
If you don't catch an unchecked exception (RuntimeException, Error, or any subclass of either),it will be passed up the call stack. If nobody catches it, the program will crash and print out the exception.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!