Edit report at https://bugs.php.net/bug.php?id=63868&edit=1
ID: 63868 User updated by: mattsch at gmail dot com Reported by: mattsch at gmail dot com Summary: PDO construct breaks exception chain Status: Not a bug Type: Bug Package: PDO related Operating System: Gentoo PHP Version: 5.3.20 Block user comment: N Private report: N New Comment: Since you declared this as not a bug quite quickly, does this mean you have no intention on allowing an unbroken exception chain within php exceptions? If that's the case, then why bother implementing exception chaining at all? It's supposed to help debugging but if the chain gets broken within php core classes, what's the point? Previous Comments: ------------------------------------------------------------------------ [2012-12-29 12:34:07] johan...@php.net This doesn't seem like anything fitting in PDO design (and btw. this affects any function which might throw an exception...) ------------------------------------------------------------------------ [2012-12-28 18:14:50] mattsch at gmail dot com Description: ------------ The pdo construct has no way of continuing the exception chain. It needs another parameter at the end so you can pass in the previous exception. For that matter, is there any kind of effort to add exception chaining parameters for all php classes that throw exceptions? Test script: --------------- <?php class MyCustomException extends Exception {} function doStuff() { try { throw new InvalidArgumentException("You are doing it wrong!", 112); } catch(Exception $e) { try { $pdo = new PDO('foo', 'foo', 'bar', array()); // exception chain lost // $pdo = new PDO('foo', 'foo', 'bar', array(), $e); // needs additional previous exception parameter } catch (Exception $ex) { throw new MyCustomException("Something happened", 911, $ex); } } } try { doStuff(); } catch(Exception $e) { do { printf("%s:%d %s (%d) [%s]\n", $e->getFile(), $e->getLine(), $e->getMessage(), $e->getCode(), get_class($e)); } while($e = $e->getPrevious()); } Expected result: ---------------- foo.php:13 Something happened (911) [MyCustomException] foo.php:10 invalid data source name (0) [PDOException] foo.php:7 You are doing it wrong! (112) [InvalidArgumentException] Actual result: -------------- foo.php:13 Something happened (911) [MyCustomException] foo.php:10 invalid data source name (0) [PDOException] ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63868&edit=1