My project using PDO exceptional handling in 'db.class.php' which is global file for all libraries which can't be changed due to impact.
In some point of time, application is trying to connect a new database and if new database is not accessible then script should ignore this error and continue the execution.
New DB connection exception is handled in 'db.class.php' and when I am trying to handle the exception while connecting a new database, somehow exception handling not working and script is stopped at that point.
If I am not handling exception while connecting to new DB, in this case also script stopped executing.
Requirement is even if DB is not connecting in this case due to any issue, script should continue the execution ignoring the error.
Code:
try {
$newDb = new DB(DB_HOST_new, DB_NAME_new, DB_USER_new, DB_PASS_new, DB_UTC_TIMEZONE);
$isDbSsConnected = true ;
} catch (PDOException $exx) {
//throw new Exception('Unable to connect');
}
db.class.php
try {
$connection = new PDO( $dsn, $username, $password );
$connection->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
if ( $utc ) {
$this->setUtc( $connection );
}
$this->connection = $connection;
self::$connections[$dsn][$username] = self::$connectionCachingEnabled ? $this->connection : NULL;
} catch ( PDOException $ex ) {
throw new DbEx( "Initialize Failed: DSN = " . $dsn, DbEx::INIT_FAILED, $ex );
}