Class PEAR_Exception

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. }

Located in /maintenance/libraries/pear/PEAR/Exception.php (line 99)

Exception
   |
   --PEAR_Exception
Class Constant Summary
Variable Summary
 mixed $_observers
 mixed $_uniqueid
Method Summary
 PEAR_Exception __construct (mixed $message, [mixed $p2 = null], [mixed $p3 = null])
 void addObserver (mixed $callback, [string $label = 'default'])
 Exception|array getCause ()
 void getCauseMessage (array &$causes)
 void getErrorClass ()
 array getErrorData ()
 void getErrorMethod ()
 void getTraceSafe ()
 int getUniqueId ()
 void removeObserver ([mixed $label = 'default'])
 void signal ()
 void toHtml ()
 void toText ()
 void __toString ()
Variables
mixed $_observers = array() (line 105)
  • static:
mixed $_uniqueid = 0 (line 106)
  • static:
Methods
Constructor __construct (line 118)

Supported signatures:

PEAR_Exception(string $message); PEAR_Exception(string $message, int $code); PEAR_Exception(string $message, Exception $cause); PEAR_Exception(string $message, Exception $cause, int $code); PEAR_Exception(string $message, array $causes); PEAR_Exception(string $message, array $causes, int $code);

PEAR_Exception __construct (mixed $message, [mixed $p2 = null], [mixed $p3 = null])
addObserver (line 146)
  • static:
void addObserver (mixed $callback, [string $label = 'default'])
  • mixed $callback:
      • A PEAR_Exception::OBSERVER_* constant
      • An array(const PEAR_Exception::OBSERVER_*, mixed $options)
    • string $label: The name of the observer. Use this if you want to remove it later with removeObserver()
    getCause (line 215)

    Returns the exception that caused this exception to be thrown

    • return: The context of the exception
    • access: public
    Exception|array getCause ()
    getCauseMessage (line 224)

    Function must be public to call on caused exceptions

    void getCauseMessage (array &$causes)
    • array &$causes
    getErrorClass (line 267)
    void getErrorClass ()
    getErrorData (line 205)

    Return specific error information that can be used for more detailed error messages or translation.

    This method may be overridden in child exception classes in order to add functionality not present in PEAR_Exception and is a placeholder to define API

    The returned array must be an associative array of parameter => value like so:

     array('name' => $name, 'context' => array(...))

    array getErrorData ()
    getErrorMethod (line 273)
    void getErrorMethod ()
    getTraceSafe (line 255)
    void getTraceSafe ()
    getUniqueId (line 159)
    • return: unique identifier for an observer
    • static:
    int getUniqueId ()
    removeObserver (line 151)
    • static:
    void removeObserver ([mixed $label = 'default'])
    signal (line 164)
    void signal ()
    toHtml (line 287)
    void toHtml ()
    toText (line 339)
    void toText ()
    __toString (line 279)
    void __toString ()
    Class Constants
    OBSERVER_DIE = -8 (line 103)
    OBSERVER_PRINT = -2 (line 101)
    OBSERVER_TRIGGER = -4 (line 102)

    Documentation generated on Fri, 10 Dec 2004 18:25:22 +0000 by phpDocumentor 1.3.0RC3