File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes ex.getNextException(); Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ex.getNextException();" Watch "ex.getNextException();" New topic
Author

ex.getNextException();

MaheshS Kumbhar
Ranch Hand

Joined: Sep 24, 2009
Posts: 188


In above code, how does the exceptions get chained to catch block. Once an exception is thrown the control is transferred to matching catch block. What I think is there can be only one exception at a time in a catch block, so I was wondering with the use of ex.getNextException() method.

Correct me if I am wrong in getting the concept.


I am slow but sure
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30753
    
156

Exception chaining is for different levels of information about the same issue rather than totally different exceptions.

See Sun's page that explains this well. The beginning is particularly informative:

It is common for Java code to catch one exception and throw another:

try {
...
} catch(YourException e) {
throw new MyException();
}

Unfortunately, the information contained in the "causative exception" (YourException in the example above) is generally lost, which greatly complicates debugging. Recognizing this problem, developers sometimes build ad hoc mechanisms to allow certain "wrapped exceptions" to contain a second exception. An accessor is generally provided to extract the contained exception. Such mechanisms are sometimes known as "exception chaining facilities", as they allow arbitrary chains of exceptions to be constructed when contained exceptions are, themselves, wrapped exceptions.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ex.getNextException();