【发布时间】:2015-02-08 16:55:57
【问题描述】:
我正在使用 Yii 2 框架,它使用了许多扩展异常,我遇到了一个问题,我抛出了一个 UserException 但它最终被基 Exception 捕获但我'不知道为什么!?
代码:
try {
//........
if ($reader->count() > 0) {
if (!$already_active) {
//.....
} else {
throw new UserException('You have already activated your account; you may continue to login.');
}
}
} catch (\Exception $e) {
// User exception above is caught in here?
} catch (UserException $e) {
// Rethrow the exception
throw $e;
}
不应该将User Exception 传递给第二个catch 并被第二个catch 捕获吗?
【问题讨论】:
标签: php yii exception-handling try-catch yii2