是否可以使用“转到"从声明中 [英] Is it okay to use "go to" from a catch statement

查看:82
本文介绍了是否可以使用“转到"从声明中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经被告知的一切都是去邪恶是邪恶的,远离他们,但我认为他们可以在这里帮助我(?).我想为用户提供一个选项,当捕获到异常并且无法解决该问题时会重新启动应用程序...

Everything I have ever been told is that go to's are evil and stay away from them, but I think they may help me here (?). I would like to provide the user an option to restart the application when an exception is caught and am having a bit of trouble wrapping my head around what to do...

我的应用程序将受到另一个进程的监视,但是在某些情况下,我希望用户能够决定要做什么而不将控制权返回给调用进程.

My application will be monitored by another process, but there are some exceptions where I want to the user to be able to decide what to do without returning control to the calling process.

像这样的可接受的"东西吗?还有其他建议吗?

Is something like this "acceptable"? Any other suggestions?

非常感谢!

int main(){

    initialize:
       try{
        //do things
       }
       catch(...)
       {
          cout<<"Would you like to try initializing again?"<<endl;

          //if yes
            goto initialize;

          //if not
          abort(); //or something...
        }

return 0;
}

推荐答案

为什么不喜欢这个?

while(true){
  //Do stuff
  if(exit){
    break;
  }
}

continue = true;
do{
  //Do stuff
  if(exit){
    continue = false;
  }
}while(continue);

这篇关于是否可以使用“转到"从声明中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆