This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes checked Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "checked Exception" Watch "checked Exception" New topic

checked Exception

kittu karan
Ranch Hand

Joined: Mar 09, 2008
Posts: 63
What is checked Exception?How can we know what exception is checked or unchecked Exception?
Christophe Verré

Joined: Nov 24, 2005
Posts: 14687

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 ]

[My Blog]
All roads lead to JavaRanch
Jun Wu

Joined: Mar 20, 2008
Posts: 14
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

Joined: Mar 20, 2008
Posts: 16
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

Joined: Mar 10, 2008
Posts: 1756

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 ]

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Please check your private messages.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: checked Exception
Similar Threads
Checked and Unchecked exceptions
If a Runtime Exception is thrown in the finalize method -
diff between checked and unchecked exceptions
hi all