aspose file tools
The moose likes Beginning Java and the fly likes chained exception Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 19216

Moving to Beginning Java.


SCJP 1.4 - SCJP 6 - SCWCD 5
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: 19216

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

mu gaandimara wrote:

Please check your private messages for an important administrative matter.


[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: chained exception
 
Similar Threads
Chained Exceptions?
Documenting chained Exceptions ?
Exception Handling - Good Practice
The throw question
Chained exception