Catching Database Connection Error And Showing An Alternate Error Page

When Yii isn’t able to connect to DB i get an error like:

CDbException

CDbConnection failed to open the DB connection

I find it ugly and it could scare away a noob user, regardless it also displays a little information about the error to frontend user which in my option is a bad practice. I have tested and site/error (the error handler i set) isn’t being called. This exception is happening somewhere outside.

Is there a way i could catch it and display an alternate error page, or redirect to site/error?

remove the line

defined(‘YII_DEBUG’) or define(‘YII_DEBUG’,true);

from your index.php or just change it from ‘true’ to ‘false’

already tried, no use.

i ended up modifying index.php and catching the exception there and forward it to my custom handler that would take care of logging, firing me an email, enabling maintenance mode if such exceptions cross a certain counter.

Though i have fixed it, i don’t think thats the prettiest way. There might be a better way but for now i am just looking for “Just works”.