Answer the question
In order to leave comments, you need to log in
How to catch Exception correctly?
How to handle Exception so standard yii2 404 page appears?
Without creating your own class and so that processing is performed for all exceptions
try
{
$activeCategory = NewsCategory::find()
->where(['name_en' => Yii::$app->request->get('category')])
->one();
$model = News::find()
->where(['newsCategory_id' => $activeCategory->id]);
} catch (Exception $ex) {
/* */
}
Answer the question
In order to leave comments, you need to log in
Add a slash before Exception in your code. Then it will work as you need.
} catch (\Exception $ex) {
throw new NotFoundHttpException('Not found');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question