aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How can we identify checked and Unchecked exceptions ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How can we identify checked and Unchecked exceptions ?" Watch "How can we identify checked and Unchecked exceptions ?" New topic
Author

How can we identify checked and Unchecked exceptions ?

vijay basky
Greenhorn

Joined: Feb 05, 2012
Posts: 18

how can we identify a particular exception is a checked or unchecked exception ?
for example how will you say NullPointerException is an Unchecked exception ?
thanks in advance
John Stark
Ranch Hand

Joined: Jul 19, 2011
Posts: 185
The documentation to the class NullPointerException (which can be found here: http://docs.oracle.com/javase/6/docs/api/) tells you that NullPointerException is a subclass of RuntimeException. Therefore it is unchecked. Any exception which is a subclass of RuntimeException is unchecked otherwise it is checked.

John
vijay basky
Greenhorn

Joined: Feb 05, 2012
Posts: 18

John Stark wrote:The documentation to the class NullPointerException (which can be found here: http://docs.oracle.com/javase/6/docs/api/) tells you that NullPointerException is a subclass of RuntimeException. Therefore it is unchecked. Any exception which is a subclass of RuntimeException is unchecked otherwise it is checked.

John


thaks for the reply and i know NullPointerException is the subtype of RuntimeException
RuntimeException and Error and their subtypes are unchecked exceptions
so we have to memorise all the checked and unchecked exceptios list ?
or is there any tricky methods to identify this ?

John Stark
Ranch Hand

Joined: Jul 19, 2011
Posts: 185
In principle RuntimeExceptions are for exceptions which occur due to programming errors. For example IllegalMonitorStateException occurs because you do a call to notify() not within a synchronized context. The FileNotFoundException occurs when the attempt to open a file fails because the file does not exist. This is in general not foreseeable by the programmer and FileNotFoundException is a checked exception. So exceptions which are not foreseeable should be handled wheres foreseeable exceptions are normally not handled. But I must admit this concept is not entirely clear to me. Maybe somebody else can explain?
For the exam I guess it is the best to know whether the most important exceptions are checked or unchecked.

John
vijay basky
Greenhorn

Joined: Feb 05, 2012
Posts: 18

John Stark wrote:In principle RuntimeExceptions are for exceptions which occur due to programming errors. For example IllegalMonitorStateException occurs because you do a call to notify() not within a synchronized context. The FileNotFoundException occurs when the attempt to open a file fails because the file does not exist. This is in general not foreseeable by the programmer and FileNotFoundException is a checked exception. So exceptions which are not foreseeable should be handled wheres foreseeable exceptions are normally not handled. But I must admit this concept is not entirely clear to me. Maybe somebody else can explain?
For the exam I guess it is the best to know whether the most important exceptions are checked or unchecked.

John


thanks for the reply john, it is a good tricky method
vijay basky
Greenhorn

Joined: Feb 05, 2012
Posts: 18

Is there anyone suggest more explanation and tricky methods other than the above one ?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

In real life the way to tell is to read the documentation for the exception, as per John's original response. Memorizing the exceptions from the standard API is not practical because anybody can write their own subclasses of Exception or of RuntimeException.

And you didn't say what exam you were referring to. In my opinion any exam which requires you to memorize which of the hundreds of exceptions in the standard API are unchecked is not an exam worth taking; but I don't believe the well-known certification exams do that.
vijay basky
Greenhorn

Joined: Feb 05, 2012
Posts: 18

Paul Clapham wrote:In real life the way to tell is to read the documentation for the exception, as per John's original response. Memorizing the exceptions from the standard API is not practical because anybody can write their own subclasses of Exception or of RuntimeException.

And you didn't say what exam you were referring to. In my opinion any exam which requires you to memorize which of the hundreds of exceptions in the standard API are unchecked is not an exam worth taking; but I don't believe the well-known certification exams do that.


i m preparing for OCPJP certification exam.I agree with you that memorizing hundreds of exceptions is not an exam worth taking and i don't want to do that, what i need is to understand the concept thoroughly, so please explain how to identify a particular Exception is checked or unchecked exception ? which is understandable
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can we identify checked and Unchecked exceptions ?