Home >PHP Framework >YII >How to catch yii2 exceptions
How to catch exceptions in yii2
All exceptions in yii are inherited from Exception. There are two ways to write exceptions
//a文件: function a() { throw new \yii\web\HttpException('我是数据库异常'); } //b文件: use yii\db\Exception;
Writing method one:
try{ a(); } catch(\yii\web\HttpException $e) { echo "捕获到异常了"; }
Writing method two:
try{ a(); } catch(\Exception $e) { echo "捕获到异常了"; }
Recommended related article tutorials: yii tutorial
The above is the detailed content of How to catch yii2 exceptions. For more information, please follow other related articles on the PHP Chinese website!