This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Error/AssertionError 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 "Doubt in Error/AssertionError " Watch "Doubt in Error/AssertionError " New topic

Doubt in Error/AssertionError

Gitesh Ramchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 274
For the following code:

What is the result?
A. end
B. Compilation fails.
C. exception end
D. exception test end
E. A Throwable is thrown by main.
F. An Exception is thrown by main.

Answer: E

output is:

Doubt: According to the answer, option E, I don't see ant Throwable thrown by main(). Is the option E wrong? Please help
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
AssertionError extends Error that extends Throwable.
So when AssertionError is thrown by main can also be said as
Error is thrown by main or
Throwable is thrown by main.
Hope that clears.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14950

Gitesh, when you copy a question from a book or mock exam, you need to quote your sources.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

Do Remember the following hirerachy :

or you can say that
Object ----> Throwable ----> Error

So if an instance of type Error is thrown then throwable can catch that, but
Exception can not.

Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Doubt in Error/AssertionError
It's not a secret anymore!