• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ex.getNextException();

 
MaheshS Kumbhar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34686
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic