简体   繁体   中英

how to continue thread execution after getting an exception

class TestA implements Runnable {
  public void run() {
    try {
      // do stuff
    } catch(Exception e) {
      // ...
    } finally {
      // ...
    }
  }
}

When an exception occurs, the control comes out of the program. I have 10 files in a for loop to be processed.

When there is an exception in the 2nd file, the remaining 8 files do not get processed. But I want a log to be created for the failure and continue processing the remaining files without terminating. Is there any way to do that? Thanks!!!

Nest your try / catch logic inside the for -loop:

for(...)
{
    try
    {
        ... // process the file
    }
    catch(...)
    {
        ... // deal with the exception
    }
}

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