Bug #63868 [Opn->Nab]: PDO construct breaks exception chain

From: Date: Sat, 29 Dec 2012 12:34:07 +0000
Subject: Bug #63868 [Opn->Nab]: PDO construct breaks exception chain
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-175650@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63868&edit=1

 ID:                 63868
 Updated by:         johannes@php.net
 Reported by:        mattsch at gmail dot com
 Summary:            PDO construct breaks exception chain
-Status:             Open
+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:

This doesn't seem like anything fitting in PDO design (and btw. this affects any function which
might throw an exception...)


Previous Comments:
------------------------------------------------------------------------
[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


Thread (3 messages)

« previous php.bugs (#175650) next »