On a default Craft install if I'm logged out and hit the front-end of the site with purposefully messed up database credentials, I get a nicely styled Craft 404 page if there is no craft/templates/404.html
and a front-end 404 page if there is.
I believe the issue is that you've got your own front-end 404 template that's also trying to access the database and it can't.
So basically the first error is thrown (can't access the database), then another error happens (I really can't access the database) when trying to tell you about the first error.
By this point, Yii thinks the error has already been handled, so it falls back to CApplication->displayException(). I assume in this case, some content header or encoding isn't set properly and you see the garbled ’ character.
So until/if we can think of a way to guard against this scenario, your best bet is to make sure that your 404 template isn't triggering a database call.
can’t
.