No of visitors who read this post: 390
Category: Java
Type: Question
No votes yet

Hi

Differentiate between Unchecked & Checked Exceptions in Java. Please tell me its complete detail

Regards.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

# Comment Id: 21267

Unchecked Exceptions:
 
Exceptions that need not be explicitly declared nor caught in the try-catch block. For e.g. StringIndexOutOfBoundsException thrown by String\'s charAt() method.
Checked Exceptions:
 
Exceptions that need to be explicitly declared and caught/handled appropriately when the method is invoked.
 

# Comment Id: 21427

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 .

# Comment Id: 21619

Hi petersulliva here is the difference between the two clarified for you below here 

UNCHECKED EXCETIONS:

  •  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)

CHECKED EXCEPTIONS:

  • 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