正如标题所示, 这是我的代码: p>
我正在尝试捕获一个异常 有人可以解释我的错误吗? 感谢您的帮助 p>
div> try / catch code>不会捕获抛出异常。 p>
public function edit($ id)
{
try {
$ this-> permissions ($ ID);
返回$ this-> redirect(['edit / list']);
} catch(Exception $ e){
Yii :: $ app-> session-> setFlash('error' ,Yii :: t('app','PERMISSIONS_NOT_FOUND'));
}
}
code> pre>
permissions() code>方法。 权限方法是: p>
私有函数persimssions($ id)
{
$ allowed = false;
if if(!$ allowed){
throw new ForbiddenHttpException(Yii :: t('app','MODULE_NO_PERMISSIONS'));
}
}
code> pre>
as the title says, try/catch
doesn't catch throwed exception.
Here is my code:
public function edit($id)
{
try {
$this->permissions($id);
return $this->redirect(['edit/list']);
} catch (Exception $e) {
Yii::$app->session->setFlash('error', Yii::t('app', 'PERMISSIONS_NOT_FOUND'));
}
}
I'm trying to catch an exception which is in permissions()
method. Permissions method is:
private function persimssions($id)
{
$permitted = false;
if (!$permitted) {
throw new ForbiddenHttpException(Yii::t('app', 'MODULE_NO_PERMISSIONS'));
}
}
Could someone explain me what is wrong? Thanks for any help