I don't know how I can catch a PDOException in the following code, please tell me where is the throw exception in the following code?
i is (directory):
- folder -1) b.php -2) c.php - autoloader
in b.php :
<?php namespace folder; use folder as x; require_once '../autoload.php'; class b{ function __construct(){ print("<p>you are in class b<p/>"); } } $t=new x\c(); ?>
and c.php :
class c{ function __construct(){ print("<p>you are in class c<p/>"); if(DB_TYPE == 'mysql') $pdoString=DB_TYPE.':dbname='.DB_NAME.';host='.DB_HOST; $pdoUsername=DB_USERNAME; $pdoPass='1';//DB_PASS; in this line I enter wrong password try{ $this->pdo = new PDO($pdoString, $pdoUsername, $pdoPass); }catch(PDOException $e){ //we can't catch exception here! die('<p> Error DataBase Connection: '.$e->getMessage()."</p>"); } } } ?>
I entered the wrong password, I expect to catch the exception in my try catch , but I get this output:
you are in class c Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)' in C:\xampp\htdocs\TEST\folder\c.php:17 Stack trace:
navid source share