简体   繁体   中英

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();}}

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,

You could use finally here.

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

} finally {
   your code
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM