• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Exceptions question

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
4. 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


i think its A , C ,D

but the answer is B,C,D

why A is wrong and the developer can test the instance throw instanceof operator and if its fails thrown ClassCastException ?
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A developer may be able to throw a ClassCastException but it is not typical (as specified by the question).

re: instanceof. If I have a method that takes an object, and I use instanceof, then I would not throw a ClassCastException. I would throw an IllegalArgumentException because that tells the client more information: that they are breaking the contract of the method.
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eisa,

You can look at various scenarios where chosen exceptions may be thrown and
handled programatically.

Try it out:



ClassCastException I may not require to tell you.





Regards,
cmbhatt
[ April 22, 2007: Message edited by: Chandra Bhatt ]
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also stick a bookmark on pg. 370 of K&B book
 
Arad Chear
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all ,

Chandra thanks for your code
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic