To catch all CDbConnection errors, you need to enable the error handler in the config / main.php file
'components'=>array('errorHandler'=>array('errorAction'=>'site/error', ), ),
Then in your controller (or an abstract base class for all your controllers) you need to define an action to perform the redirect.
public function actionError() { if($error=Yii::app()->errorHandler->error) if ( CDbException == $error->type) { $this->redirect(array("site/error_message")); }
Alternatively, you can simply visualize your custom views:
public function actionError() { if($error=Yii::app()->errorHandler->error) if ( CDbException == $error->type) { $this->render('error', $error); } }
See Yii docs for more details.
hobs source share