• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checked Exception

 
kittu karan
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is checked Exception?How can we know what exception is checked or unchecked Exception?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A checked exception is an exception that you'll have to catch or rethrow, otherwise the compiler won't be happy. It's like saying that you're throwing eggs and there's nobody to catch them Checked exceptions extend the Exception class.
[ March 21, 2008: Message edited by: Christophe Verre ]
 
Jun Wu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi kiran peruka,the checked exception is a exception which you must try-catch or throws it,otherwise java compiler will angry! On the contrary ,you can try -catch unchecked exception ,or not,the complier doesn't complaint you !
 
Nikhil Raj
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A checked exception is any exception that the compiler will check whether you are handling or not. If a code throws a checked exception, you should use a try catch block to catch it or add a throws clause to the method.
otherwise the compiler will report an error.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can indeed determine whether an exception is a checked exception or an unchecked exception at compile-time, by waiting for the compiler to complain about the catch or specify requirement. If you don't have that luxury (e.g. on an SCJP exam), you can also determine this by looking at the exception's type hierarchy. Only subclasses of java.lang.Error and java.lang.RuntimeException are unchecked. Everything else is checked.
[ March 21, 2008: Message edited by: Jelle Klap ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic