File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Error/AssertionError

 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 637
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gitesh, when you copy a question from a book or mock exam, you need to quote your sources.
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic