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

后端 未结 7 836
灰色年华
灰色年华 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; }
      }
    }
    

提交回复
热议问题