This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes ExceptionWrapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "ExceptionWrapping" Watch "ExceptionWrapping" New topic


jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
How and why do we use exception wrapping in java? Any sample program would be really helpful.
Shinelin Samuel
Ranch Hand

Joined: Mar 01, 2010
Posts: 55
Hi Jose,

If you are looking for own customized exception for your application. You can extend the respective Exception class and call Super constructors and usally override the methods available in Exception (getCause() and getException() methods).

To your information, all exceptions in Java are extened from java.lang.Exception. For example java.lang.ClassNotFoundException is extended from java.lang.Exception.

Another one, java.sql.BatchUpdateException is extended from java.sql.SQLException and SQLException has java.lang.Exception as its Base class.
Shinelin Samuel
Ranch Hand

Joined: Mar 01, 2010
Posts: 55
and to your question why use wrapped Exception ?? It is to localize the exception for a specific Code, Application or API. Also, it provides more information about, and helps in identifying, where the exception has occured.
jQuery in Action, 2nd edition
subject: ExceptionWrapping