[Solved] Cdbexception Not Being Rendered In View

I have a constraint on a field in a table that the particular field must be unique. If I try and create a new client and use an id that is not unique I generate a CDbException error. I would like this error to be gracefully handled by a view rather than the getting "CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation:…etc" being written to the browser.

In my main config file I have:



			// use 'site/error' action to display errors


In my sitecontroller is

public function actionError()




			if ( CDbException == $error->type) {

           		$this->redirect(array("site/error")); }

			else if(Yii::app()->request->isAjaxRequest) {

				echo $error['message']; }


				$this->render('error', $error);



And I have a view in the …views\site\error.php

How can I have the error displayed in a view rather than the CDbException being written straight to the browser?

Solved - Need to remove the YII_DEBUG code in index.php