C,这个goto声明有保证吗?
发布时间:2020-12-16 05:51:43 所属栏目:百科 来源:网络整理
导读:我稍稍改变了标题,因为我认为这是更恰当的问题. 你会重构吗(好像合法使用goto)? 如果,你如何重构以下代码来删除转到语句? if (data.device) { try { ... } catch(const std::exception) { goto done; } ... // more things which should not be caughtdone
我稍稍改变了标题,因为我认为这是更恰当的问题.
你会重构吗(好像合法使用goto)? if (data.device) { try { ... } catch(const std::exception&) { goto done; } ... // more things which should not be caught done: ; } 完整的声明 #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: ; } #endif 谢谢 之后看到了大多数的偏好,我决定和旗一起去,但是约克先生的评论. 谢谢大家 解决方法if (data.device) { bool status = true; try { ... } catch(std::exception) { status = false; } if (status) { ... // more things which should not be caught } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |