exception.php 981 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. // Set the exception code
  22. $this->code = $inner->getCode();
  23. }
  24. /**
  25. * Get the inner exception.
  26. *
  27. * @return Exception
  28. */
  29. public function getInner()
  30. {
  31. return $this->inner;
  32. }
  33. /**
  34. * Set the exception message to include the SQL and bindings.
  35. *
  36. * @param string $sql
  37. * @param array $bindings
  38. * @return void
  39. */
  40. protected function setMessage($sql, $bindings)
  41. {
  42. $this->message = $this->inner->getMessage();
  43. $this->message .= "\n\nSQL: ".$sql."\n\nBindings: ".var_export($bindings, true);
  44. }
  45. }