0

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();}}
2
  • I'm not sure what you mean recall the same method, but maybe you are looking for the finally block that will always execute even if there is no error? Commented Apr 21, 2014 at 16:05
  • Well my code calls abondon() inside a catch block of another abandon(). Commented Apr 21, 2014 at 18:22

2 Answers 2

1

following is some pseudo-code:

List errorIndexList = new ArrayList();

for(...) {
    if (i + 1 < lc.size()) {
        try {
            lc.get(i + 1).abondon();
        } catch (AbandonException e1) {
            errorIndexList.add(i+1);
            // do some error handle work ..
            // print error log/info if need,
            continue; // this is optional, in case it's the last statement,
        }
    }
}

// use errorIndexList to handle your errors, if need,
Sign up to request clarification or add additional context in comments.

Comments

0

You could use finally here.

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

} finally {
   your code
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.