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

Class: PEAR_Exception

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

Class Overview

Exception
   |
   --PEAR_Exception

Base PEAR_Exception Class


Author(s):

Version:

  • Release: 1.10.12

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

Class Details

[line 96]
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 101]

  • Access: protected

Type:   mixed


[ Top ]



Method Detail

__construct (Constructor)   [line 120]

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

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

    Exception|array getCause( )

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

    [ Top ]

    getCauseMessage   [line 233]

    void getCauseMessage( array &$causes)

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

    Parameters:

    array   &$causes   — 

    [ Top ]

    getErrorClass   [line 302]

    void getErrorClass( )

    • Access: public

    [ Top ]

    getErrorData   [line 214]

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

    void getErrorMethod( )

    • Access: public

    [ Top ]

    getTraceSafe   [line 290]

    void getTraceSafe( )

    • Access: public

    [ Top ]

    getUniqueId   [line 168]

    int getUniqueId( )

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

    [ Top ]

    removeObserver   [line 160]

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

    • Access: public

    Parameters:

       $label   — 

    [ Top ]

    toHtml   [line 322]

    void toHtml( )

    • Access: public

    [ Top ]

    toText   [line 376]

    void toText( )

    • Access: public

    [ Top ]

    __toString   [line 314]

    void __toString( )

    • Access: public

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


    Documentation generated on Sun, 19 Apr 2020 14:22:13 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.