In my application I have never used chained exception. But I am really looking forward to use it as I believe it can make my code better. But being new to it can someone provide me with some example as in what type of scenario and how can it be used?
Asked
Active
Viewed 98 times
-2
-
Not really clear but what you mean by chained exception, where did you come across the concept? – Elemental Jul 11 '13 at 07:13
-
Possible duplicate of http://stackoverflow.com/questions/5020876/what-is-the-advantage-of-chained-exceptions – Raedwald Jan 20 '16 at 18:32
2 Answers
3
The following example shows how to use a chained exception.
try {
} catch (IOException e) {
throw new SampleException("Other IOException", e);
}
In this example, when an IOException
is caught, a new SampleException
exception is created with the original cause
attached and the chain of exceptions
is thrown up to the next higher level exception
handler.

Suresh Atta
- 120,458
- 37
- 198
- 307
0
Try like this
try{
.....
}catch(ArithmeticExecption e){
....
}
.
.
.// u can add various exceptions like this
catch(Exception e){
....
}
//And if you are not sure which exception to use , use the more
general exception ,like i mentioned above

Vamsi Pavan Mahesh
- 240
- 1
- 8
- 30