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

Class: PEAR_Exception

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

Class Overview

Exception
   |
   --PEAR_Exception

Base PEAR_Exception Class


Author(s):

Version:

  • Release: 1.9.5

Copyright:

  • 1997-2009 The Authors

Variables

Methods


Inherited Variables

Class: Exception (Internal Class)

$code
$file
$line
$message
$previous
$string
$trace

Inherited Methods

Class: Exception (Internal Class)

constructor __construct ( [$message = ], [$code = ], [$previous = ] )
getCode ( )
getFile ( )
getLine ( )
getMessage ( )
getPrevious ( )
getTrace ( )
getTraceAsString ( )
__clone ( )
__toString ( )

Class Details

[line 97]
Base PEAR_Exception Class

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 ]


Class Variables

$cause =

[line 102]

  • Access: protected

Type:   mixed


[ Top ]



Method Detail

__construct (Constructor)   [line 121]

PEAR_Exception __construct( string $message, [int|Exception|PEAR_Error|array|null $p2 = null], [int|null $p3 = null])

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, PEAR_Error $cause);
  • PEAR_Exception(string $message, PEAR_Error $cause, int $code);
  • PEAR_Exception(string $message, array $causes);
  • PEAR_Exception(string $message, array $causes, int $code);

  • Access: public

Overrides Exception::constructor __construct ( [$message = ], [$code = ], [$previous = ] ) (parent method not documented)

Parameters:

string   $message     exception message
int|Exception|PEAR_Error|array|null   $p2     exception cause
int|null   $p3     exception code or null

[ Top ]

addObserver   [line 156]

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

  • Access: public

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 225]

    Exception|array getCause( )

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

    [ Top ]

    getCauseMessage   [line 234]

    void getCauseMessage( array &$causes)

    Function must be public to call on caused exceptions
    • Access: public

    Parameters:

    array   &$causes     

    [ Top ]

    getErrorClass   [line 303]

    void getErrorClass( )

    • Access: public

    [ Top ]

    getErrorData   [line 215]

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

    • Access: public

    [ Top ]

    getErrorMethod   [line 309]

    void getErrorMethod( )

    • Access: public

    [ Top ]

    getTraceSafe   [line 291]

    void getTraceSafe( )

    • Access: public

    [ Top ]

    getUniqueId   [line 169]

    int getUniqueId( )

    • Return: unique identifier for an observer
    • Access: public

    [ Top ]

    removeObserver   [line 161]

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

    • Access: public

    Parameters:

       $label     

    [ Top ]

    toHtml   [line 323]

    void toHtml( )

    • Access: public

    [ Top ]

    toText   [line 377]

    void toText( )

    • Access: public

    [ Top ]

    __toString   [line 315]

    void __toString( )

    • Access: public

    Overrides Exception::__toString ( ) (parent method not documented)
    [ Top ]


    Documentation generated on Sat, 12 Jul 2014 14:00:44 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.