N/APosted on - 07/31/2011
Differentiate between Unchecked & Checked Exceptions in Java. Please tell me its complete detail
Exceptions that need not be explicitly declared nor caught in the try-catch block. For e.g. StringIndexOutOfBoundsException thrown by String's charAt() method.
Exceptions that need to be explicitly declared and caught/handled appropriately when the method is invoked.
The difference is checked exceptions must be explicitly caught or propagated checked exceptions in Java extend the java.lang.Exception class. While as unchecked exceptions do not have to be caught or declared thrownunchecked exceptions are Runtime Exception and any of its subclasses. Class Error and its subclasses also are uncheckedexceptions extend the java.lang.RuntimeException .
Hi petersulliva here is the difference between the two clarified for you below here
It represents defect in program (bugs) or errors- often invalid arguments gets passed to non private methods. To get quote from The Java Programming Language, by Gosling, Arnold "Unchecked runtime exceptions represent conditions that, or generally speaking, reflects errors in programs logic and can’t be reasonably recovered from run time."
are also subclasses of RuntimeException, and are implemented using IllegalArgumentException, NullPointerException.
a method is not used to establish a policy for unchecked exceptions occurred by its implementation (and they almost always do not do so)
It represents invalid conditions in areas present outside immediate control of program.
are subclasses of exception
Checked exception is also a method to establish a policy for all checked exceptions occurred by implementation either pass the checked exception further upwards in the stack or handle it somehow