• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

chained exception

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is chained exception ???
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Beginning Java.
 
mu gaandimara
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we wrap a Checked Exception in a RuntimeException ??
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

mu gaandimara wrote:


Please check your private messages for an important administrative matter.
 
Greenhorn
Posts: 3
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chained exception is a feature introduced with JDK 1.4, which allow developers to associate an exception with another exception.
For example, suppose you encounter an ArithmeticException because of a division by zero, however the actual cause of the error is because of an IO error which caused the divisor to the set incorrectly. Chained exception helps us to identify such cases i.e. cause of an exception.

Below is an article you might want to read for further understanding:
http://www.cubearticle.com/articles/core-java/basics/chained-exception
 
Did you miss me? Did you miss this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic