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...
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With