Exception.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\db;
  8. /**
  9. * Exception represents an exception that is caused by some DB-related operations.
  10. *
  11. * @author Qiang Xue <qiang.xue@gmail.com>
  12. * @since 2.0
  13. */
  14. class Exception extends \yii\base\Exception
  15. {
  16. /**
  17. * @var array the error info provided by a PDO exception. This is the same as returned
  18. * by [PDO::errorInfo](https://secure.php.net/manual/en/pdo.errorinfo.php).
  19. */
  20. public $errorInfo = [];
  21. /**
  22. * Constructor.
  23. * @param string $message PDO error message
  24. * @param array $errorInfo PDO error info
  25. * @param int $code PDO error code
  26. * @param \Exception $previous The previous exception used for the exception chaining.
  27. */
  28. public function __construct($message, $errorInfo = [], $code = 0, \Exception $previous = null)
  29. {
  30. $this->errorInfo = $errorInfo;
  31. parent::__construct($message, $code, $previous);
  32. }
  33. /**
  34. * @return string the user-friendly name of this exception
  35. */
  36. public function getName()
  37. {
  38. return 'Database Exception';
  39. }
  40. /**
  41. * @return string readable representation of exception
  42. */
  43. public function __toString()
  44. {
  45. return parent::__toString() . PHP_EOL
  46. . 'Additional Information:' . PHP_EOL . print_r($this->errorInfo, true);
  47. }
  48. }