ralphschindler/zf2 — Issue #23: Exception codes
Author: till
Created: 2012-02-25 16:58:04+00:00
State: open

One of my gribes with Zend_Db in ZF1 – the exception codes are null (or were made null).

This means that when an exception is thrown, it's left to the developer to parse the actual exception message to figure out what happened.

I'd like something like this:

// pseudo code, not tested
use \Zend\Db as DB;
use \Zend\Db\Exception as DBException;

try {
$db->query("INSERT INTO foo VALUES('bar')");
} catch (DBException $e) {
if ($e->getCode() == DB::ERR_DUPLICATE) {
// handle this
} else {
throw $e;
}
}

This would allow developers to see what went wrong. I realize this requires some kind of mapping in the drivers, etc., but I think this is a very useful feature for a DBAL.