Tutorial :C++ , is this goto statement warranted?


I have changed title slightly because I thought this is more appropriate question.

Would you refactor it (seems like legitimate use of goto) ? If, how would you refactor the following code to remove go to statement?

if (data.device) {      try {          ...      }      catch(const std::exception&) { goto done; }      ... // more things which should not be caught  done: ;  }  

complete statement

#ifdef HAVE_GPU              // attempt to use GPU device              if (data.device) {                  try {                      Integral::Gpu eri(S, R, Q, block.shell());                      eri(basis.centers(), quartets, data.device);                  }                  // if GPU fails, propagate to cpu                  catch(std::exception) { goto done; }                  data.device += size;                  host_index.extend(block_index);                  block_index.data.clear();              done: ;              }  

Next Post »