permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception Doubt" Watch "Exception Doubt" New topic
Author

Exception Doubt

Ashok Pradhan
Ranch Hand

Joined: Dec 17, 2007
Posts: 180

What is the diffrence between Checked Exception and unchecked Exception.
is that runtime exceptions are unchecked Exceptions and they are derived from RuntimeException.
Denise Advincula
Ranch Hand

Joined: Jan 01, 2007
Posts: 160
Checked Exceptions are always checked by the Compiler. The compiler throws errors if the Checked exceptions are not handled or declared.

Unchecked Exceptions on the other hand are not checked by the compiler and yes, they are subclasses of RuntimeException. Whether you choose to handle or declare them, the compiler doesn't care.

More on this topic: http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html

Hope this helps.


SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCMJEA in progress...
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
For Checked Exceptions you need try-catch blocks. You need not try-catch Unchecked(Runtime) Exceptions.

Thanks.


Be Humble... Be Nice.
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

All throws exception are Checked Exception.Compiler makes sure that a block capable of throwing a CheckedException must/should associate a handler for it.Which if neglected would generate a compile-time error.
Example : Block having a Class.forName("class name") statement should throw(s) ClassNotFoundException. Neglecting a handler for Unchecked exception doesn't worry compiler.


Thanks & Regards
Sidharth Pallai
Ashok Pradhan
Ranch Hand

Joined: Dec 17, 2007
Posts: 180

IllegalArgumentException is a checked Exception or UnChecked Exception.
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Hi Ashok,
IllegalArgumentException is definetly an Unchecked Runtime Exception,which would prop-up during runtime when when a method is invoked with an argument which it can not reasonably deal with.
Check for categorised exceptions,you will know the list.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

Originally posted by Ashok Pradhan:
IllegalArgumentException is a checked Exception or UnChecked Exception.

To find the answer, lookup IllegalArgumentException in the API documentation to find out whether it is a subclass of RuntimeException or not.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ashok Pradhan
Ranch Hand

Joined: Dec 17, 2007
Posts: 180

Is that mean all the checked Exceptions are not RuntimeException and they are not either direct subclass or subclass of subclasses.
[ June 30, 2008: Message edited by: Ashok Pradhan ]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

Yes - Any exception that has RuntimeException as a superclass (either direct or higher up the inheritance chain) is an unchecked exception, and other exceptions are checked exceptions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception Doubt
 
Similar Threads
Checked and uncheked exceptions
K&B question - overriding methods
Exceptions and interfaces
How to recognise a checked or unchecked exception
what is the difference between checked and unchecked exceptions