Can't you pass the error code to the QueryError like in http://php.net/manual/de/mysqli.errno.php Or maybe sth more interoperable with PgSql, like an QueryExecutionError?