• 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

difference between exceptions thrown by us and thrown by the jvm

 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there is a question in masterlabs that which one of these are thrown by us and not by jvm?

1.classcastexception
2.numberformatexception
3.illegalstateexception
4.illegalargumentexception
5.exceptionininitializer

why is the answer only b,c,d not nothing else...? and when is the 5th exception thrown?

thank you
 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below mentioned is the code which generates ExceptionInInitializer at runtime


 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but isnt this arrayindexoutofboundsexception?
 
Ranch Hand
Posts: 71
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You won't throw ClassCastException and ExceptionInInitializer when writing codes. Those are thrown by the JVM when such exceptional condition occurs. The other three are thrown by the developers that developed the Java API. So I think it is considered to be thrown by "us".

ExceptionInInitializer could be thrown when there's something wrong in a static block. E.g.

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Ankur i think you will find suitable explanation in k&b book in exception handling chapter.
And for your question answer are follows:

1. ClassCastException Thrown when attempting to cast a reference By the JVM
variable to a type that fails the IS-A test.

2.NumberFormatException Thrown when a method that converts a
String to a number receives a String that it Programmatically
cannot convert

3.IllegalStateException Thrown when the state of the environment Programmatically
doesn’t match the operation being attempted,
e.g., using a Scanner that’s been closed.

4.IllegalArgumentException Thrown when a method receives an argument Programmatically
formatted differently than the method
expects.

5.ExceptionInInitializerError Thrown when attempting to initialize a static By the JVM
variable or an initialization block.

Hope you understand
 
Sheriff
Posts: 9708
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

Ankur kothari wrote:there is a question in masterlabs


What is masterlabs??
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
masterexams
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh right rohan...i need to understand that table in the book....thanks everyone
 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I did not understand the question at first time.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic