This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception thrown by an API developer or JVM  RSS feed

 
Rajesh Chandra
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I bumped into this question

Which are most typically thrown by an API developer or an application developer as opposed to being thrown by the JVM? (Choose all that apply.)


A). ClassCastException
B). IllegalStateException
C). NumberFormatException
D). IllegalArgumentException
E). ExceptionInInitializerError

The answer is B,C and D.
My confusion is whether the question is about checked and unchecked exception.If so why option A is not part of answer?

regs-Rajesh
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rajesh Chandra:

My confusion is whether the question is about checked and unchecked exception.If so why option A is not part of answer?


You are right.

B,C and D are checked exception, while A and E are unchecked.
 
Eric McIntyre
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the question isn't really about checked vs. unchecked, but simply which are "system-level" exceptions and which are "user-level". A & E are typically thrown by the JVM in response to system events - classloading in the case of A, and static initializers for E. An API/application developer would not (and should not) normally throw them. The others are more indicative of an application problem, such as trying to reuse a closed resource (IllegalStateException).
 
Rajesh Chandra
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Eric but how do we know which are "system-level" exceptions and which are "user-level".
rajesh
 
Eric McIntyre
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Practice The javadocs also come in handy. Look through the exceptions and errors in java.lang to get a feel. All system exceptions and errors are in that package, I believe.

Also, I just realized this morning, NumberFormatException is the only one of those that is a checked exception. All the rest extend RuntimeException or Error.

Hope this helps
Eric
 
Rob Spoor
Sheriff
Posts: 21089
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chetan Parekh:


You are right.

B,C and D are checked exception, while A and E are unchecked.

Actually, B, C and D all extend RuntimeException and therefore are unchecked as well.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!