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 chained exception 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 "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: 19538
    
  16

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: 19538
    
  16

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: 9990
    
    7

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!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: chained exception
 
Similar Threads
Chained Exceptions?
Chained exception
Exception Handling - Good Practice
The throw question
Documenting chained Exceptions ?