Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt in Error/AssertionError  RSS feed

 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • 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
  • Likes 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
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • 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
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!