wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes True statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "True statement" Watch "True statement" New topic
Author

True statement

meena latha
Ranch Hand

Joined: Jan 24, 2005
Posts: 219
1.The Error class is an untime Exception.
2.No Exception are subclass of Error.
3.Any statement that throws an Error must be enclosed in the try block.
4.Any statement that throws an EXception must be enclosed in the try block.
5.Any statement that might throw an RuntimeException must be enclosed in the try block.

I thought the correct statement is 2.
But it was 4.
How come.....according to statement 4 RuntimeException should be also caught in the try block which is not true.

Correct me if i am wrong....

Akash Roy
Greenhorn

Joined: Jan 08, 2005
Posts: 16
Hi,
I think you are partially correct. RuntimeExceptions and Error class are unchecked Exceptions. Hence they need not be enclosed in try-catch block.
All the rest throwables including Exception are checked Exceptions. Hence they need to be enclosed in try-catch Block.Hence 4 is the correct answer.

But option 2 sounds a bit confusing....
Regards,
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Statment 4 is not really true - instead of using a try-catch block, you may simply delare that the exception is thrown by the surrounding method. (Which, in turn, will mean that you must try/catch or declare the exception in any other methods which call this method.) For example:

The only correct answer here is 2, as Ramya said. Ignore the "official" answer here - it's wrong. Wherever you got this question - don't trust the source. They are confused.


"I'm not back." - Bill Harding, Twister
Monica Moncho
Ranch Hand

Joined: Dec 01, 2004
Posts: 31
But if I create an exception from Exception I should catch it or throw it. In general, subclasses of exceptions should be also try-catch, but RuntimeException is an exception (common English language exception here) to the rule.

Is this not correct? I don't understand then why 4 is ok because RuntimeException is an Exception and it doesn't have to be in try.

I am making any sense?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Statement 4 is not OK. It's wrong. It's a poorly-worded question, and the person who originally wrote it gave the incorrect answer.
[ February 10, 2005: Message edited by: Jim Yingst ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: True statement