DBAL-371: DBALException doesn't forward the SQL exception code #1561

doctrinebot opened this Issue Oct 24, 2012 · 3 comments

2 participants


Jira issue originally created by user mnapoli:

PDO exceptions carry the SQL error code. However DBALException doesn't forward any error code from the SQL exception.

Here is a (really poor/quick) example of usage:

try {
} catch (DBALException $e) {
    if ($e->getCode() === 23000) {
        echo '';
    } else {
        throw $e;

I think I found where the problem is:

public static function driverExceptionDuringQuery(\Exception $driverEx, $sql, array $params = array())
    $msg = "An exception occurred while executing '".$sql."'";
    if ($params) {
        $msg .= " with params ".json_encode($params);
    $msg .= ":\n\n".$driverEx->getMessage();

    return new self($msg, 0, $driverEx);

In return new self($msg, 0, $driverEx);, the exception is created with an error code of 0.

Is there a reason for this: is that that the driver exception may not always have a defined error code? (for example if the sql driver is not PDO or the SQL system doesn't support that, but in this case then the error code would be 0 would that be a problem?)


Comment created by mnapoli:

Pull request here: #221


Comment created by @doctrinebot:

A related Github Pull-Request [GH-221] was closed:


Issue was closed with resolution "Won't Fix"

@doctrinebot doctrinebot added the Bug label Dec 6, 2015
@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment