-
-
Save chrisguitarguy/e021918900e93dca304d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class AbstractPlatform | |
{ | |
//... | |
/** | |
* Throw a more specific exception based on a SQL error code. | |
* | |
* @param \PDOException $e | |
* @throws \Doctrine\DBAL\DBALException | |
* @return void | |
*/ | |
public function throwException(\PDOException $e) | |
{ | |
$error_class = substr((string)$e->getCode(), 0, 2); | |
switch ($error_class) { | |
// Connection Exception | |
case '08': | |
// pass, connection exceptions seem to be handled elsewhere? | |
break; | |
case '0A': | |
case '0a': | |
$exception = 'FeatureNotSupportedException'; | |
break; | |
case '21': | |
$exception = 'CardinalityViolationException'; | |
break; | |
case '22': | |
$exception = 'DataException'; | |
break; | |
case '23': | |
$exception = 'IntegrityConstraintException'; | |
break; | |
case '24': | |
$exception = 'InvalidCursorStateException'; | |
break; | |
case '25': | |
$exception = 'InvalidTransationStateException'; | |
break; | |
// ... how many of these do the drivers actual use? | |
} | |
if (isset($exception)) { | |
$exception = 'Doctrine\\DBAL\\Exception\\' . $exception; | |
throw new $exception($e->getMessage(), 0, $e); | |
} | |
// if all else fails, just throw a DBALException | |
throw new DBALException($e->getMessage(), 0, $e); | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment