Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what are checked and unchecked exceptions ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what are checked and unchecked exceptions ?" Watch "what are checked and unchecked exceptions ?" New topic

what are checked and unchecked exceptions ?

teja dharma
Ranch Hand

Joined: Feb 07, 2009
Posts: 51
can any body tell me what are checked and unchecked exceptions with one simple example.

Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
If you have any code that might throw a checked exception, you must either enclose it in a try/catch clause that handles that potential exception, or must declare the checked exception in a throws clause in the containing method. Basically, the compiler will check that you do that with code that potentially throws checked exceptions. The compiler doesn't care about unchecked exceptions.

All code in my posts, unless a source is explicitly mentioned, is my own.
Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
teja hyd wrote: can any body tell me what are checked and unchecked exceptions with one simple example.

check this link :Exceptions

<a href="" target="_blank" rel="nofollow">My Techie Blog</a><br /><a href="" target="_blank" rel="nofollow">Java Questions</a>
dhanabal vellingiri

Joined: Apr 02, 2007
Posts: 1
Checked -> Exceptions caught by compiler
unchecked -> Exceptions not caught by compiler( you can write your own catch block to catch at runtime )
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

Exceptions are never caught by the compiler, because exceptions happen at runtime, not at compile time.

Checked exceptions are exceptions that are checked by the compiler - in other words, the compiler checks to see if you handle them with a try ... catch block, or declare that you throw them further with a throws-clause in the method declaration. If you don't handle or declare a checked exception in a throws-clause, the compiler will stop with an error.

Unchecked exceptions are not checked by the compiler - you do not need to catch them or declare them with a throws-clause.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
It is sorta covered in the JavaRanch Style Guide.
subject: what are checked and unchecked exceptions ?
Similar Threads
checked and Unchecked exceptions
Questions from mock Exam !!!
checked & unchecked exceptions
Is Throwble a checked Exception