GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 445 of 502    Print  
What is difference between checked and unchecked exception ?

  
Total Answers and Comments: 5 Last Update: September 05, 2008     Asked by: Veera SEkhar 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
October 25, 2007 03:42:09   #1  
psuresh1982 Member Since: September 2006   Contribution: 1027    

RE: What is difference between checked and unchecked e...
checked Exceptions must be dealt with in either a try/catch block or by declaring a "throws" in a method. Unchecked exceptions normally are Runtime exceptions like NullPointerException or ClassCastException.

A simple rule of thumb: If it's an exception you can possibly deal with (continue to run the program using some alternative code) use checked exceptions. For exceptions that should never happen (if they do it's a bug) use unchecked (Runtime) exceptions which will come up to the surface and displayed to the user. Like this you assure that if there's a bug it will show up eventually and can be fixed and you don't run the risk of catching an exception and forgetting to deal with it (f.i.
empty catch block).

Also if you want more details then go through the following URL....

http://www.javapractices.com/Topic129.cjp

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
November 16, 2007 08:58:13   #2  
aneesm Member Since: November 2007   Contribution: 3    

RE: What is difference between checked and unchecked e...

Unchecked exceptions are those exceptions that are not mentioned after throws clause.
Checked exceptions are those which are mentioned in the throws clause


 
Is this answer useful? Yes | No
February 14, 2008 01:25:59   #3  
sampra Member Since: February 2008   Contribution: 278    

RE: What is difference between checked and unchecked exception ?
checked exp is complie time exception or caught excep eg aerithmatic exp
unchecked is runtim excption or uncaught excep eg virtual memory

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
June 09, 2008 04:51:35   #4  
kiranmai.kasturi Member Since: June 2008   Contribution: 4    

RE: What is difference between checked and unchecked exception ?
checked exception is compile time exception which inherit "Exception" and unchecked exception is Rintime exception which is subclass of "RuntimeException"
 
Is this answer useful? Yes | No
September 05, 2008 05:48:46   #5  
muktasharad Member Since: September 2008   Contribution: 4    

RE: What is difference between checked and unchecked exception ?
checked exceptions must be handeled.That is a try-catch must either be nested around the call to the method that throws the exception.The compiler will throw an error message if it detects an uncaught exception and will not compile the file.

The run-time exceptions(unchecked exceptions) do not have to be caught. This avoids requiring that a try-catch be place around for example every integer division operation to catch a divide by zero or around every array variable to watch for indices going out of bounds.

You can use multiple catch clauses to catch the different kinds of exceptions that code can throw as shown in this snippet:

try
{
... some code...
}
catch (ArrayIndexOutOfBoundException e)
{
...
}
catch (IOException e)
{
...
}
catch (Exception e)
{
...
}
finally
// optional
{
...this code always executed even if
no exceptions...
}



 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape