I want to catch Databasethe database connection refuse/denied/not found exceptions with a custom handler. I have already buildbuilt an handler which is overriding drupalthe default logger factory.
But, but now I want to use thethat custom handler to log database exceptions as mentioned, without hacking the core.
I can see mysqlthe connection driver uses the following code in open() function asopen()
.
try {
$pdo = new \PDO($dsn, $connection_options['username'], $connection_options['password'], $connection_options['pdo']);
}
catch (\PDOException $e) {
if ($e->getCode() == static::DATABASE_NOT_FOUND) {
throw new DatabaseNotFoundException($e->getMessage(), $e->getCode(), $e);
}
if ($e->getCode() == static::ACCESS_DENIED) {
throw new DatabaseAccessDeniedException($e->getMessage(), $e->getCode(), $e);
}
throw $e;
}
But I am not sure how I can catch the exception and log it using custom handler without hacking the corehandler. How can I achieve this?