Reputation: 371
I insert an entry in which there is a duplicate of the primary key.
public function actionInc()
{
$add = new Country();
$add->code = 'QI';
$add->name = 'Qiang';
$add->population = '4444444';
try {
$add->save();
return $this->render('inc', [
'count' => 'Ok',
]);
} catch (Exception $exception) {
return $this->render('inc', [
'count' => 'Error',
]);
}
}
But I need that the application does not down, and continued to work, but it does not work...
Upvotes: 4
Views: 10161
Reputation: 2382
check which Exception subclass you are importing in your use statements
yii throws \yii\db\Exception
for db-related errors.
all of yii's exceptions inherit from \Exception
// db related exceptions
catch (\yii\db\Exception $exception)
// any exception throwin by yii
catch (\yii\base\Exception $exception)
// any php exception
catch (\Exception $exception)
Upvotes: 8