Differentiate between Unchecked & Checked Exceptions

Asked By 30 points N/A Posted on -
qa-featured

Hi

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

Regards.

SHARE
Best Answer by James20
Best Answer
Best Answer
Answered By 5 points N/A #96088

Differentiate between Unchecked & Checked Exceptions

qa-featured

 

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.
 
Answered By 0 points N/A #96090

Differentiate between Unchecked & Checked Exceptions

qa-featured

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 .

Answered By 0 points N/A #96092

Differentiate between Unchecked & Checked Exceptions

qa-featured

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  

 

 

Related Questions