【发布时间】:2015-02-03 08:02:02
【问题描述】:
我有这个代码:
<?php
[...]
// Authentication error
catch(AuthException $e)
{
// TODO: Save fault to auth into DB
// Propagate exception
throw $e;
}
// Common exception
catch(Exception $e)
{
// TODO: Log error here
$response = JsonResponse(array("error" => $e->getMessage()));
$response->send();
}
我希望能够抛出 AuthException 和 Exception,并希望确保 AuthException 的 catch 将错误存储到 db 中,并且作为常见的 Exception 将作为错误返回。 但是现在我有错误,我有未发现的异常。 或者我可能需要在 AuthException 的构造函数中记录错误?
【问题讨论】:
-
你在被捕获后抛出异常,所以如果你没有另一层代码可以捕获它并对其进行处理,你将有一个
Uncaught exception错误 -
为什么不简单地在
$response的catch(AuthException $e)块中添加一列?