I wish to show a custom error page on Joomla for error messages like

Could not connect to database server

How is this done ?

you'll find joomla error page's template in /templates/system/error.php You are able to copy this file for your template's root folder and edit it.