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();}}
LonsomeHell
  • 573
  • 1
  • 7
  • 29
  • 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? – Justin C Apr 21 '14 at 16:05
  • Well my code calls abondon() inside a catch block of another abandon(). – LonsomeHell Apr 21 '14 at 18:22

2 Answers2

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,
Eric
  • 22,183
  • 20
  • 145
  • 196
0

You could use finally here.

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

} finally {
   your code
}
fastcodejava
  • 39,895
  • 28
  • 133
  • 186