125 }
elseif (is_object($p2) || is_array($p2)) {
127 if (is_object($p2) && !($p2 instanceof Exception)) {
128 if (!class_exists(
'PEAR_Error') || !($p2 instanceof PEAR_Error)) {
130 'exception cause must be Exception, ' .
131 'array, or PEAR_Error'
136 if (is_array($p2) && isset($p2[
'message'])) {
145 parent::__construct($message, $code);
163 self::$_observers[$label] = $callback;
175 unset(self::$_observers[$label]);
185 return self::$_uniqueid++;
195 foreach (self::$_observers as $func) {
196 if (is_callable($func)) {
197 call_user_func($func, $this);
200 settype($func,
'array');
202 case self::OBSERVER_PRINT :
203 $f = (isset($func[1])) ? $func[1] :
'%s';
204 printf($f, $this->getMessage());
206 case self::OBSERVER_TRIGGER :
207 $f = (isset($func[1])) ? $func[1] : E_USER_NOTICE;
208 trigger_error($this->getMessage(), $f);
210 case self::OBSERVER_DIE :
211 $f = (isset($func[1])) ? $func[1] :
'%s';
212 die(printf($f, $this->getMessage()));
215 trigger_error(
'invalid observer type', E_USER_WARNING);
260 $cause = array(
'class' => get_class($this),
261 'message' => $this->message,
263 'line' =>
'unknown');
264 if (isset($trace[0])) {
265 if (isset($trace[0][
'file'])) {
266 $cause[
'file'] = $trace[0][
'file'];
267 $cause[
'line'] = $trace[0][
'line'];
272 $this->cause->getCauseMessage($causes);
273 }
elseif ($this->cause instanceof Exception) {
274 $causes[] = array(
'class' => get_class($this->cause),
275 'message' => $this->cause->getMessage(),
276 'file' => $this->cause->getFile(),
277 'line' => $this->cause->getLine());
278 }
elseif (class_exists(
'PEAR_Error') && $this->cause instanceof PEAR_Error) {
279 $causes[] = array(
'class' => get_class($this->cause),
280 'message' => $this->cause->getMessage(),
282 'line' =>
'unknown');
283 }
elseif (is_array($this->cause)) {
284 foreach ($this->cause as
$cause) {
285 if ($cause instanceof PEAR_Exception) {
286 $cause->getCauseMessage($causes);
287 }
elseif ($cause instanceof Exception) {
288 $causes[] = array(
'class' => get_class($cause),
289 'message' => $cause->getMessage(),
290 'file' => $cause->getFile(),
291 'line' => $cause->getLine());
292 }
elseif (class_exists(
'PEAR_Error')
293 && $cause instanceof PEAR_Error
295 $causes[] = array(
'class' => get_class($cause),
296 'message' => $cause->getMessage(),
298 'line' =>
'unknown');
299 }
elseif (is_array($cause) && isset($cause[
'message'])) {
302 'class' => $cause[
'package'],
303 'message' => $cause[
'message'],
304 'file' => isset($cause[
'context'][
'file']) ?
305 $cause[
'context'][
'file'] :
307 'line' => isset($cause[
'context'][
'line']) ?
308 $cause[
'context'][
'line'] :
323 if (!isset($this->_trace)) {
324 $this->_trace = $this->getTrace();
325 if (empty($this->_trace)) {
326 $backtrace = debug_backtrace();
327 $this->_trace = array($backtrace[count($backtrace)-1]);
341 return $trace[0][
'class'];
352 return $trace[0][
'function'];
365 if (isset($_SERVER[
'REQUEST_URI'])) {
381 $html =
'<table style="border: 1px" cellspacing="0">' .
"\n";
382 foreach ($causes as $i =>
$cause) {
383 $html .=
'<tr><td colspan="3" style="background: #ff9999">'
384 . str_repeat(
'-', $i) .
' <b>' .
$cause[
'class'] .
'</b>: '
385 . htmlspecialchars(
$cause[
'message'])
386 .
' in <b>' .
$cause[
'file'] .
'</b> '
387 .
'on line <b>' .
$cause[
'line'] .
'</b>'
390 $html .=
'<tr><td colspan="3" style="background-color: #aaaaaa; text-align: center; font-weight: bold;">Exception trace</td></tr>' .
"\n"
391 .
'<tr><td style="text-align: center; background: #cccccc; width:20px; font-weight: bold;">#</td>'
392 .
'<td style="text-align: center; background: #cccccc; font-weight: bold;">Function</td>'
393 .
'<td style="text-align: center; background: #cccccc; font-weight: bold;">Location</td></tr>' .
"\n";
395 foreach ($trace as $k => $v) {
396 $html .=
'<tr><td style="text-align: center;">' . $k .
'</td>'
398 if (!empty($v[
'class'])) {
399 $html .= $v[
'class'] . $v[
'type'];
401 $html .= $v[
'function'];
403 if (!empty($v[
'args'])) {
404 foreach ($v[
'args'] as $arg) {
407 }
else if (is_array($arg)) {
409 }
else if (is_object($arg)) {
410 $args[] =
'Object('.get_class($arg).
')';
411 }
else if (is_bool($arg)) {
412 $args[] = $arg ?
'true' :
'false';
413 }
else if (is_int($arg) || is_double($arg)) {
417 $str = htmlspecialchars(substr($arg, 0, 16));
418 if (strlen($arg) > 16) {
421 $args[] =
"'" . $str .
"'";
425 $html .=
'(' . implode(
', ', $args) .
')'
427 .
'<td>' . (isset($v[
'file']) ? $v[
'file'] :
'unknown')
428 .
':' . (isset($v[
'line']) ? $v[
'line'] :
'unknown')
429 .
'</td></tr>' .
"\n";
431 $html .=
'<tr><td style="text-align: center;">' . ($k+1) .
'</td>'
433 .
'<td> </td></tr>' .
"\n"
448 foreach ($causes as $i =>
$cause) {
449 $causeMsg .= str_repeat(
' ', $i) .
$cause[
'class'] .
': '
451 .
' on line ' .
$cause[
'line'] .
"\n";
453 return $causeMsg . $this->getTraceAsString();