wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes chained exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "chained exception" Watch "chained exception" New topic
Author

chained exception

mu gaandimara
Greenhorn

Joined: Aug 04, 2009
Posts: 10
What is chained exception ???
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
When you wrap an exception that is the root cause in another exception.

The Servlet Spec makes use of it.

the doGet, doPost etc. methods of HttpServlet throw a ServletException.

Imagine code like this.



You chain the SQLException together with the ServletException since you cannot throw it yourself (the signature does not allow this)

ServletException itself has a method called getRootCause() that returns the Exception you chained.


JDBCSupport - An easy to use, light-weight JDBC framework -
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Moving to Beginning Java.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
mu gaandimara
Greenhorn

Joined: Aug 04, 2009
Posts: 10
Can we wrap a Checked Exception in a RuntimeException ??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Sure. If the class does not have a constructor that has a Throwable parameter for the cause, you can always set the cause later:

And please read your private messages regarding an important announcement.

Thank you,

Rob
mu gaandimara
Greenhorn

Joined: Aug 04, 2009
Posts: 10
thank you
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10169
    
    8

mu gaandimara wrote:

Please check your private messages for an important administrative matter.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: chained exception
 
Similar Threads
Chained exception
The throw question
Chained Exceptions?
Documenting chained Exceptions ?
Exception Handling - Good Practice