exception.php 914 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php namespace Laravel\Database;
  2. class Exception extends \Exception {
  3. /**
  4. * The inner exception.
  5. *
  6. * @var Exception
  7. */
  8. protected $inner;
  9. /**
  10. * Create a new database exception instance.
  11. *
  12. * @param string $sql
  13. * @param array $bindings
  14. * @param Exception $inner
  15. * @return void
  16. */
  17. public function __construct($sql, $bindings, \Exception $inner)
  18. {
  19. $this->inner = $inner;
  20. $this->setMessage($sql, $bindings);
  21. }
  22. /**
  23. * Get the inner exception.
  24. *
  25. * @return Exception
  26. */
  27. public function getInner()
  28. {
  29. return $this->inner;
  30. }
  31. /**
  32. * Set the exception message to include the SQL and bindings.
  33. *
  34. * @param string $sql
  35. * @param array $bindings
  36. * @return void
  37. */
  38. protected function setMessage($sql, $bindings)
  39. {
  40. $this->message = $this->inner->getMessage();
  41. $this->message .= "\n\nSQL: ".$sql."\n\nBindings: ".var_export($bindings, true);
  42. }
  43. }