File/maintenance/libraries/pear/PEAR/Exception.php

Description

Base PEAR_Exception Class

WARNING: This code should be considered stable, but the API is subject to immediate and drastic change, so API stability is at best alpha

1) Features:

  • Nestable exceptions (throw new PEAR_Exception($msg, $prev_exception))
  • Definable triggers, shot when exceptions occur
  • Pretty and informative error messages
  • Added more context info available (like class, method or cause)
  • cause can be a PEAR_Exception or an array of mixed PEAR_Exceptions/PEAR_ErrorStack warnings
  • callbacks for specific exception classes and their children
2) Ideas:

  • Maybe a way to define a 'template' for the output
3) Inherited properties from PHP Exception Class:

protected $message protected $code protected $line protected $file private $trace

4) Inherited methods from PHP Exception Class:

__clone __construct getMessage getCode getFile getLine getTraceSafe getTraceSafeAsString __toString

5) Usage example

  1. require_once 'PEAR/Exception.php';
  2.  
  3. class Test {
  4. function foo() {
  5. throw new PEAR_Exception('Error Message', ERROR_CODE);
  6. }
  7. }
  8.  
  9. function myLogger($pear_exception) {
  10. echo $pear_exception->getMessage();
  11. }
  12. // each time a exception is thrown the 'myLogger' will be called
  13. // (its use is completely optional)
  14. PEAR_Exception::addObserver('myLogger');
  15. $test = new Test;
  16. try {
  17. $test->foo();
  18. } catch (PEAR_Exception $e) {
  19. print $e;
  20. }

Classes
Class Description
 class PEAR_Exception Base PEAR_Exception Class

Documentation generated on Fri, 11 Feb 2005 18:13:06 +0000 by phpDocumentor 1.3.0RC3