exception.php 791 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. * Set the exception message to include the SQL and bindings.
  24. *
  25. * @param string $sql
  26. * @param array $bindings
  27. * @return void
  28. */
  29. protected function setMessage($sql, $bindings)
  30. {
  31. $this->message = $this->inner->getMessage();
  32. $this->message .= "\n\nSQL: ".$sql."\n\nBindings: ".var_export($bindings, true);
  33. }
  34. }