Source for file Exception.php
Documentation is available at Exception.php
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 The PEAR Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Tomas V.V.Cox <cox@idecnet.com> |
// | Hans Lellelid <hans@velum.net> |
// +----------------------------------------------------------------------+
// $Id: Exception.php,v 1.1 2004/08/19 18:28:15 gurugeek Exp $
define('PEAR_OBSERVER_PRINT', -2 );
define('PEAR_OBSERVER_TRIGGER', -4 );
define('PEAR_OBSERVER_DIE', -8 );
* Base PEAR_Exception Class
* - Nestable exceptions (throw new PEAR_Exception($msg, $prev_exception))
* - Definable triggers, shot when exceptions occur
* - Pretty and informative error messages
* - Added more context info avaible (like class, method or cause)
* - Maybe a way to define a 'template' for the output
* 1) Inherited properties from PHP Exception Class:
* 2) Inherited methods from PHP Exception Class:
* require_once 'PEAR/Exception.php';
* throw new PEAR_Exception('Error Message', ERROR_CODE);
* function myLogger($pear_exception) {
* echo $pear_exception->getMessage();
* // each time a exception is thrown the 'myLogger' will be called
* // (its use is completely optional)
* PEAR_Exception::addObserver('mylogger', 'myLogger');
* } catch (PEAR_Exception $e) {
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Hans Lellelid <hans@velum.net>
private static $_observers = array ();
* PEAR_Exception(string $message);
* PEAR_Exception(string $message, int $code);
* PEAR_Exception(string $message, Exception $cause);
* PEAR_Exception(string $message, Exception $cause, int $code);
public function __construct($message, $p2 = null , $p3 = null )
if (is_int($p3) && $p2 instanceof Exception ) {
} elseif ($p2 instanceof Exception ) {
$trace = parent ::getTrace ();
parent ::__construct ($message, $code);
self ::$_observers[$label] = $callback;
unset (self ::$_observers[$label]);
private function signal ()
foreach (self ::$_observers as $func) {
if (is_callable ($func)) {
$f = (isset ($func[1 ])) ? $func[1 ] : '%s';
printf($f, $this->getMessage ());
$f = (isset ($func[1 ])) ? $func[1 ] : E_USER_NOTICE;
$f = (isset ($func[1 ])) ? $func[1 ] : '%s';
die (printf($f, $this->getMessage ()));
$msg = ' ' . $obj->method . " at {$obj->file } ({$obj->line })\n";
if ($obj->cause instanceof Exception ) {
return $msg. $obj->getCauseMessage ($obj->cause );
* @return Exception_object The context of the exception
' Error message: ' . $this->message . "\n" .
' Error code : ' . $this->code . "\n" .
' File (Line) : ' . "{ $this->file} ({ $this->line})\n " .
' Method : ' . $this->method . "\n";
if ($this->cause instanceof Exception ) {
if (isset($_SERVER['REQUEST_URI'])) {
return nl2br('<pre>'.htmlentities($str).'</pre>');
Documentation generated on Mon, 11 Mar 2019 13:55:48 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|