• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Doubt

 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For Checked Exceptions you need try-catch blocks. You need not try-catch Unchecked(Runtime) Exceptions.

Thanks.
 
Sidharth Pallai
Ranch Hand
Posts: 134
Hibernate Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IllegalArgumentException is a checked Exception or UnChecked Exception.
 
Sidharth Pallai
Ranch Hand
Posts: 134
Hibernate Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15448
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15448
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic