Why Yii2 is down with try/catch?

Viewed 9103

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... screenshot

1 Answers
Related