Search code examples
javaexceptiontry-catch-finallymulti-catch

Handling multiple exceptions in java


My abandon() may throw AbandonException.

While handling the exception I have to recall the same method if there some element left in the Vector.

How should I proceed? And if I am not thinking straight, what would be the best solution?

   if (i + 1 < lc.size()) {
    try {
        lc.get(i + 1).abondon();
    }
    catch (AbandonException e1) {
lc.get(i+2).abandon();}}

Solution

  • You could use finally here.

    try {
          lc.get(i + 1).abondon();
    }
    catch (AbandonException e1) {
    
    } finally {
       your code
    }