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

Class: PEAR_Exception

Source Location: /PEAR_Exception-1.0.0/PEAR/Exception.php

Class Overview

Exception
   |
   --PEAR_Exception

Base PEAR_Exception Class


Author(s):

Version:

  • Release: 1.0.0

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 95]
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 100]

  • 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 161]

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

Add an exception observer
  • Access: public

Parameters:

mixed   $callback   —  - A valid php callback, see php func is_callable()
  • 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 245]

Exception|array getCause( )

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

[ Top ]

getCauseMessage   [line 257]

void getCauseMessage( &$causes, array $causes)

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

Parameters:

array   $causes   —  Array that gets filled.
   &$causes   — 

[ Top ]

getErrorClass   [line 338]

string getErrorClass( )

Gets the first class of the backtrace
  • Return: Class name
  • Access: public

[ Top ]

getErrorData   [line 235]

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

string getErrorMethod( )

Gets the first method of the backtrace
  • Return: Method/function name
  • Access: public

[ Top ]

getTraceSafe   [line 321]

array getTraceSafe( )

Build a backtrace and return it
  • Return: Backtrace
  • Access: public

[ Top ]

getUniqueId   [line 183]

int getUniqueId( )

Generate a unique ID for an observer
  • Return: unique identifier for an observer
  • Access: public

[ Top ]

removeObserver   [line 173]

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

Remove an exception observer
  • Access: public

Parameters:

string   $label   —  Name of the observer

[ Top ]

signal   [line 193]

void signal( )

Send a signal to all observers
  • Access: protected

[ Top ]

toHtml   [line 376]

string toHtml( )

Generates a HTML representation of the exception
  • Return: HTML code
  • Access: public

[ Top ]

toText   [line 443]

string toText( )

Generates text representation of the exception and stack trace
  • Access: public

[ Top ]

__toString   [line 363]

string __toString( )

Converts the exception to a string (HTML or plain text)

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


Documentation generated on Mon, 11 Mar 2019 16:01:20 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.