Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exceptions????

 
raymond yadao
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
 
Barkat Mardhani
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.
 
Satpal Chander
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 ]
 
Ron Newman
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