I have a simple piece of code, using PDO in PHP:
$conn = new PDO('mysql:host=localhost;dbname=someDatabase', $username, $password,
array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_PERSISTENT => false,
));
and this custom exception handler:
function my_exceptionHandler($exception) {
echo "Exception: {$exception->getMessage()}";
}
set_exception_handler("my_exceptionHandler");
Although the custom exception handler catches all the other exceptions, but it fails to catch the PDO-exceptions i.e. when the username and password for database are incorrect, and I just get the plain error:
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
Is there anything I miss like a overloading custom exception handler function for this type of exceptions? And note that when I wrapped the PDO code in try and catch block, it worked fine but I want to catch it in my custom exception handler.