php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63868 PDO construct breaks exception chain
Submitted: 2012-12-28 18:14 UTC Modified: 2012-12-29 16:12 UTC
From: mattsch at gmail dot com Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.3.20 OS: Gentoo
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mattsch at gmail dot com
New email:
PHP Version: OS:

 

 [2012-12-28 18:14 UTC] 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]


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-29 12:34 UTC] johannes@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-29 12:34 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2012-12-29 16:12 UTC] mattsch at gmail dot com
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?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 09:01:29 2024 UTC