为什么有些人抛出异常后会返回? [英] Why do some people return after they throw Exceptions?

查看:203
本文介绍了为什么有些人抛出异常后会返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Github上的一些代码中看到了

I see in some of the code on Github

if($something_funky_happens){
  throw new \LogicException(...);
  return;
}

这是必需的,还是不重要?
,因为我知道在引发异常后脚本将停止,因此其他代码将无法运行

Is this required, or it is not important to return? because I know that after you throw exceptions the script stops, so further code does not run

推荐答案

无法访问的代码



我倾向于将其表示为他们的代码中的错误。该语句无法到达。每个静态代码分析工具都会抱怨此无法访问的语句。即使在这种情况下它没有害处,您在检查代码时也会收到大量警告。如果关闭这些警告类型,您可能会错过代码中的其他逻辑错误。这确实是难闻的气味,需要解决。

unreachable code

I tend to denote it an error in their code. The statement is not reachable. Every static code anaylsis tool will complain about this unreachable statement. Even when it has no harm in this case you will get a load of warnings when checking your code. If you turn these warning type off you will perhaps miss other logic errors within your code. It's a real bad smell and it needs to be fixed.

这篇关于为什么有些人抛出异常后会返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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