14 private $shortMessage;
16 public function __construct($message =
'', $code = 0, \Exception $previous =
null)
18 parent::__construct($message, $code, $previous);
19 $this->shortMessage = $message;
31 $this->exceptions = array();
33 $this->
add($exception);
46 public function add($e)
48 $this->exceptions[] = $e;
50 $this->message .=
"\n";
53 $this->message .= $this->getExceptionMessage($e, 0);
63 public function count()
65 return count($this->exceptions);
75 return new \ArrayIterator($this->exceptions);
85 return $this->exceptions ? $this->exceptions[0] :
null;
88 private function getExceptionMessage(\Exception $e, $depth = 0)
91 $prefix = $depth ? str_repeat($sp, $depth) :
'';
92 $message =
"{$prefix}(" . get_class($e) .
') ' . $e->getFile() .
' line ' . $e->getLine() .
"\n";
94 if ($e instanceof
self) {
95 if ($e->shortMessage) {
96 $message .=
"\n{$prefix}{$sp}" . str_replace(
"\n",
"\n{$prefix}{$sp}", $e->shortMessage) .
"\n";
99 $message .=
"\n" . $this->getExceptionMessage($ee, $depth + 1);
102 $message .=
"\n{$prefix}{$sp}" . str_replace(
"\n",
"\n{$prefix}{$sp}", $e->getMessage()) .
"\n";
103 $message .=
"\n{$prefix}{$sp}" . str_replace(
"\n",
"\n{$prefix}{$sp}", $e->getTraceAsString()) .
"\n";
106 return str_replace(getcwd(),
'.', $message);