What is considered best practicingOr, would it be better to have a "catch-all" in terms of placement ofmy index.php (I use MVC) to catch general exceptions (for example, PDO related), and then if I need more specific ones in my application (for example, those thrown when connecting to 3rd party services), then add additional try-block catches for them: inside of a wrapper class or within the app specific logic?
In my index.php, which all requests pass through via my .htaccess file:
try { $db = new Db(); $db->connect(['host'=>DB_HOST,'dbname'=>DB_NAME,'username'=>DB_USERNAME,'password'=>DB_PASSWORD]); $bootstrap = new Bootstrap(); $bootstrap->setControllerPath('application/controllers'); $bootstrap->setModelPath('application/models'); $bootstrap->init(); //load the controller/model/classes } (catch Exception $e) { //log error //if ajax request return json_encoded message other redirect to error page }