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