DriverException.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Doctrine\DBAL\Exception;
  3. use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException;
  4. use Doctrine\DBAL\Exception;
  5. /**
  6. * Base class for all errors detected in the driver.
  7. *
  8. * @psalm-immutable
  9. */
  10. class DriverException extends Exception
  11. {
  12. /**
  13. * The previous DBAL driver exception.
  14. *
  15. * @var DeprecatedDriverException
  16. */
  17. private $driverException;
  18. /**
  19. * @param string $message The exception message.
  20. * @param DeprecatedDriverException $driverException The DBAL driver exception to chain.
  21. */
  22. public function __construct($message, DeprecatedDriverException $driverException)
  23. {
  24. parent::__construct($message, 0, $driverException);
  25. $this->driverException = $driverException;
  26. }
  27. /**
  28. * Returns the driver specific error code if given.
  29. *
  30. * Returns null if no error code was given by the driver.
  31. *
  32. * @return int|string|null
  33. */
  34. public function getErrorCode()
  35. {
  36. return $this->driverException->getErrorCode();
  37. }
  38. /**
  39. * Returns the SQLSTATE the driver was in at the time the error occurred, if given.
  40. *
  41. * Returns null if no SQLSTATE was given by the driver.
  42. *
  43. * @return string|null
  44. */
  45. public function getSQLState()
  46. {
  47. return $this->driverException->getSQLState();
  48. }
  49. }