This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes exceptions???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "exceptions????" Watch "exceptions????" New topic


raymond yadao
Ranch Hand

Joined: Jan 29, 2001
Posts: 88
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?

Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
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

Joined: Oct 02, 2002
Posts: 1
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.
[ October 02, 2002: Message edited by: Satpal Chander ]
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
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.

Ron Newman - SCJP 1.2 (100%, 7 August 2002)
I agree. Here's the link:
subject: exceptions????
It's not a secret anymore!