File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes why extend Exception instead of Throwable ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why extend Exception instead of Throwable ?" Watch "why extend Exception instead of Throwable ?" New topic
Author

why extend Exception instead of Throwable ?

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798

We usually extend Exception instead of Throwable. Why? In what situations we extend Throwable.

Thanks.

nitin pokhriyal
Ranch Hand

Joined: May 19, 2005
Posts: 263
It is not necessary to extend from exception but a good programing practice. If you look at the Exception hierarchy it has a parallel to Error which is child of throwable.
More generally in application you create your own exception hierarchies.
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Edward,

There's no real reason to extend Throwable, unless Sun decides to develop a third type of exceptional condition (I'm not sure what that would be, though).

John.
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Edward Chen wrote:
We usually extend Exception instead of Throwable. Why? In what situations we extend Throwable.

Never extends throwable, extends Exception or an existing subclass of Exception as you want to add another kind of Exception not a kind of Throwable. You can extends RuntimeException if you need your exception to be unchecked.


http://muhammadkhojaye.blogspot.com/
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Because "Throwable" is too non-specific. Don't know whether the Java™ Tutorials section is any help.
Vikash Ananda
Ranch Hand

Joined: Oct 12, 2009
Posts: 32
Hi,

As you can see the specs throwable has 2 child hierarchies namely error and exception. Error are "serious" errors that a program generally shouldn't expect to catch and recover from while Exceptions are errors that a program can reasonably recover from.

Hence we should try to use Exceptions in all our applications.

Thanks,
Vikash Anand.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: why extend Exception instead of Throwable ?
 
Similar Threads
Doubt on Throwble interface
throw Exception
How do I go about making my own Yahoo Messenger?
Why Throwable is a class?
Why extend RuntimeException?