David Harris David Harris - 1 year ago 110
SQL Question

PDO claims uncaught exception, even though it's inside of try/catch block?

Well err, I don't know what I did wrong....

This code:

try {
} catch(PDOException $e) {
$this->raiseError('Fatal MySQL error', $e->getMessage());

Reports this to me:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000] [1049] Unknown database 'pasteaes'' in /var/www/pasteaes/common/class.pasteaes.php on line 25

But, as you can see it is clearly in a try and catch block.

The class that this particular piece of code is in is namespaced, which is why I used "\PDO" instead of "PDO" on line two of the code I shared above.

And oh, yeah, I know that the DB doesn't exist, but I still don't want this happening in the future (not that it will). I want to handle errors properly :(

Answer Source
catch(\PDOException $e)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download