AbstractException.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\DBAL\Driver;
  4. use Doctrine\Deprecations\Deprecation;
  5. use Exception as BaseException;
  6. /**
  7. * Base implementation of the {@link Exception} interface.
  8. *
  9. * @internal
  10. *
  11. * @psalm-immutable
  12. */
  13. abstract class AbstractException extends BaseException implements DriverException
  14. {
  15. /**
  16. * The driver specific error code.
  17. *
  18. * @var int|string|null
  19. */
  20. private $errorCode;
  21. /**
  22. * The SQLSTATE of the driver.
  23. *
  24. * @var string|null
  25. */
  26. private $sqlState;
  27. /**
  28. * @param string $message The driver error message.
  29. * @param string|null $sqlState The SQLSTATE the driver is in at the time the error occurred, if any.
  30. * @param int|string|null $errorCode The driver specific error code if any.
  31. */
  32. public function __construct($message, $sqlState = null, $errorCode = null)
  33. {
  34. parent::__construct($message);
  35. $this->errorCode = $errorCode;
  36. $this->sqlState = $sqlState;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function getErrorCode()
  42. {
  43. /** @psalm-suppress ImpureMethodCall */
  44. Deprecation::triggerIfCalledFromOutside(
  45. 'doctrine/dbal',
  46. 'https://github.com/doctrine/dbal/pull/4112',
  47. 'Driver\AbstractException::getErrorCode() is deprecated, use getSQLState() or getCode() instead.'
  48. );
  49. return $this->errorCode;
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function getSQLState()
  55. {
  56. return $this->sqlState;
  57. }
  58. }