在try catch块是不好的返回内的catch?这是良好的做法 [英] In the try catch block is it bad to return inside the catch? which is good practice

查看:112
本文介绍了在try catch块是不好的返回内的catch?这是良好的做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在try catch块中,从C ++的catch块中返回值是不好的做法吗?

  try 
{
//有些代码...
return 1;
}
catch(...)
{
return 0;使用try / catch的方法是否是最佳做法?

$ <$ p $>



解决方案

不,只要返回的值意味着你想要的,你可以随时返回。
(如果已分配,请确保已清除内存)。


In the try catch block is it bad practice to return values from the catch block in C++?

try
{
    //Some code...
    return 1;
}
catch(...)
{
    return 0;
}

Which method of using try/catch is good practice?

解决方案

No, As long as the returned value means what you wanted it to be, you can return anytime. (make sure you've cleared memory if allocated).

这篇关于在try catch块是不好的返回内的catch?这是良好的做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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