Let’s say I have method a() and method b() which both may throw an exception. In my program, there is a situation where I have to call at least one of them; it doesn’t matter which I call. However, if one of them throws an exception, I have to call the other one. If they both throw an exception, I don’t have to do anything.
I was thinking of doing something like this:
try {
a();
catch (Exception e) {
try {
b();
catch (Exception e) {
}
}
but I thought this would be impractical if I had more than two methods to call. So I was wondering if there were a more elegant or better way to do something I’m trying to do.
you can
if the chain is even longer, probably better