• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SCJP question.

 
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the question asked in Katy siera 1.5.
Chapter 5 question no 16.
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 they had given is B,C,D
my doubt is C. NumberFormatException is the exception thrown by JVM means in runtime. how come the answer is true. pleaes clarify me is NumberFormatException is runtime exception or compile time exception.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to SCJP forum.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not asking you to distinguish runtime vs compile time exceptions.

Which are most typically thrown by an API developer

(A) extends RuntimeException and also (C) extends (D) so your reasoning is incorrect.

You can see the "Use" of a class by clicking on Use at the top or bottom of the API page.
Here is the link for NFE
For example in class Integer, public static int parseInt(String s) throws NumberFormatException

If you lookup ExceptionInInitializerError you will see there are no uses.



 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well basically the thing is, JVM exceptions are automatically thrown by the JVM. Like NullPointerException. That occurs at runtime when you try to access a property or method on a null reference. It is thrown automatically by the JVM. Although you can throw it explicitly using the throw clause, but usually this is not done.

And then there is a second type of exceptions, which are not thrown automatically by the JVM. Like the NumberFormatException for instance. There is no way that the JVM will automatically throw that exception. It will always have to be thrown using a throw clause. So if the parseInt method throws this exception, then there would be a throw clause inside the parseInt method to throw this exception



So this type of exception is thrown by the developers instead of being thrown by the JVM. JVM exceptions are limited to a few and only a few of the total exceptions are covered on the exam...
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot friends now i got it.....
 
Hang a left on main. Then read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic