In addition to supporting the default signature of the built-in Exception class, PEAR2\Exception also supports passing a cause of an exception, which can be another exception object or a PEAR2_MultiErrors object. The error messages of the causes are used when constructing the error message displayed when converting PEAR2\Exception to a string.

PEAR2\Exception should always be extended by your own custom exception class for the package.

Release Notes - 0.2.0

  • Covert namespace to PEAR2
  • Removed getCause() as it just uses the built in getPrevious() that was added in PHP 5.3
  • Removed getUniqueId as it's used anywhere
  • Removed toHtml, toText and __toString (which only handled calling the former two). People should implement their owny decorator calls.
  • Removed the built in outputs of the observer functions. Those where the class constants OBSERVER_PRINT, OBSERVER_TRIGGER, OBSERVER_DIE This can be achieved by writing a custom callback function, using the appropriate printf(), trigger_error and die() to achieve the same result.
  • Removed getErroClass and getErrorMethod as it can be easily gotten from getTrace/getTraceSafe first array element
  • Add the proper LICENSE file and move Exception.php to the NEW BSD license as the package.xml already defines
  • Removed __toString, toText and toHtml. For those wanting to get pretty outputs they can use this approach:

    $causes = array(); $this->getCauseMessage($causes); foreach ($causes as $i => $cause) { var_dump($cause); }

    And combine that with getTraceSafe() or getTraceAsString() if needed.

    Put all that in a function and use set_exception_handler('exceptionHandler'); or similar to process all Exceptions.

    Example code or see the removed code at :

    function exceptionHandler($e) { if ($e instanceof \PEAR2\Exception) { $causes = array(); $e->getCauseMessage($causes); $causeMsg = ''; foreach ($causes as $i => $cause) { $causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': ' . $cause['message'] . "\n"; } echo $causeMsg; } else { echo $e->getMessage(), "\n"; } }




$ php pyrus.phar install PEAR2_Exception
Status: 0.2.0 alpha, released on May 23, 2010
License: New BSD License

Release History

0.2.0 alpha May 23, 2010
0.1.0 alpha July 7, 2009

Browse Files

6 files in 8 directories.

Dependencies for PEAR2_Exception

  • PHP ≥ 5.2.0