【发布时间】:2014-12-03 09:31:58
【问题描述】:
问题在于不允许应用程序抛出异常并且不要在非关键元素中停止应用程序(可消耗的,例如保存到数据库的用户搜索的日志历史记录)是否更好地使用此代码:
try {
/* some code here that will throw an exception at any error/miss-configuration because it is the
way this module works */
$user = Sentry::getUser();
} catch (Exception $e) {}
或:
@$user = Sentry::getUser();
这只是一个理论代码,但实际上 Sentry 是一个很好的例子来说明我的意思。在这种情况下,如果用户没有登录,那么 Sentry 会抛出异常。
正如我所说,这只是关于对应用程序不重要的代码,我不会过度使用。
显然更好的方法是编写代码来完全防止这种情况。 但是有时需要 stfu 系统:)
【问题讨论】:
标签: php try-catch operator-keyword error-reporting