Note that there are some explanatory texts on larger screens.

plurals
  1. POnot catching PDOException in namespace
    primarykey
    data
    text
    <p>I can't know how can i catch <code>PDOException</code> in the follow code,please tell me where throw exception in the follow code? </p> <p>i have (directory) :</p> <pre><code> - folder -1) b.php -2) c.php - autoloader </code></pre> <p>in the <code>b.php</code> :</p> <pre><code>&lt;?php namespace folder; use folder as x; require_once '../autoload.php'; class b{ function __construct(){ print("&lt;p&gt;you are in class b&lt;p/&gt;"); } } $t=new x\c(); ?&gt; </code></pre> <p>and in <code>c.php</code>: <pre><code>class c{ function __construct(){ print("&lt;p&gt;you are in class c&lt;p/&gt;"); 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-&gt;pdo = new PDO($pdoString, $pdoUsername, $pdoPass); }catch(PDOException $e){ //we can't catch exception here! die('&lt;p&gt; Error DataBase Connection: '.$e-&gt;getMessage()."&lt;/p&gt;"); } } } ?&gt; </code></pre> <p>I enter wrong password,i expect that have catch the exception in my <code>try catch</code> block but have this output:</p> <pre><code> 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: #0 C:\xampp\htdocs\TEST\folder\c.php(17): PDO-&gt;__construct('mysql:dbname=kn...', 'root', '1') #1 C:\xampp\htdocs\TEST\folder\b.php(10): folder\c-&gt;__construct() #2 {main} thrown in C:\xampp\htdocs\TEST\folder\c.php on line 17 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload