Is it possible to execute the code in the try block again after an exception in caught in catch block?

后端 未结 7 844
灰色年华
灰色年华 2021-02-05 06:18

I want to execute the code in the try block again after an exception is caught. Is that possible somehow?

For Eg:

try
{
    //execute some code
}
catch(E         


        
相关标签:
7条回答
  • 2021-02-05 06:55

    This should work:

    count = 0;
    while (!done) {
      try{
        //execute some code;
        done = true;
      }
      catch(Exception e){
      // code
      count++;
      if (count > 1) { done = true; }
      }
    }
    
    0 讨论(0)
提交回复
热议问题