PEAR
[ class tree: PEAR ] [ index: PEAR ] [ all elements ]

Class: PEAR_Exception

Source Location: /PEAR-1.3.3.1/PEAR/Exception.php

Class Overview

Exception
   |
   --PEAR_Exception

Base PEAR_Exception Class


Author(s):

Version:

  • $Revision: 1.4.2.1 $

Methods


Inherited Variables

Inherited Methods


Class Details

[line 99]
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 }



[ Top ]


Method Detail

addObserver   [line 146]

void addObserver( mixed $callback, [string $label = 'default'])


Parameters:

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()

    [ Top ]

    getCause   [line 215]

    Exception|array getCause( )

    Returns the exception that caused this exception to be thrown
    • Return: The context of the exception
    • Access: public

    [ Top ]

    getCauseMessage   [line 224]

    void getCauseMessage( array &$causes)

    Function must be public to call on caused exceptions

    Parameters:

    array   &$causes     

    [ Top ]

    getErrorClass   [line 267]

    void getErrorClass( )


    [ Top ]

    getErrorData   [line 205]

    array getErrorData( )

    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(...))
     


    [ Top ]

    getErrorMethod   [line 273]

    void getErrorMethod( )


    [ Top ]

    getTraceSafe   [line 255]

    void getTraceSafe( )


    [ Top ]

    getUniqueId   [line 159]

    int getUniqueId( )

    • Return: unique identifier for an observer

    [ Top ]

    removeObserver   [line 151]

    void removeObserver( [mixed $label = 'default'])


    [ Top ]

    signal   [line 164]

    void signal( )


    [ Top ]

    toHtml   [line 287]

    void toHtml( )


    [ Top ]

    toText   [line 339]

    void toText( )


    [ Top ]


    Documentation generated on Mon, 11 Apr 2005 14:34:11 -0400 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.