• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

True statement

 
meena latha
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Monica Moncho
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic