Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402]

PEAR_Exception PHP versions 4 and 5

Author: Tomas V. V. Cox <cox@idecnet.com>
Author: Hans Lellelid <hans@velum.net>
Author: Bertrand Mansion <bmansion@mamasam.com>
Author: Greg Beaver <cellog@php.net>
Copyright: 1997-2009 The Authors
License: http://opensource.org/licenses/bsd-license.php New BSD License
Version: CVS: $Id$
File Size: 389 lines (14 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

PEAR_Exception:: (14 methods):
  __construct()
  addObserver()
  removeObserver()
  getUniqueId()
  signal()
  getErrorData()
  getCause()
  getCauseMessage()
  getTraceSafe()
  getErrorClass()
  getErrorMethod()
  __toString()
  toHtml()
  toText()


Class: PEAR_Exception  - X-Ref

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

<code>
require_once 'PEAR/Exception.php';

class Test {
function foo() {
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');
$test = new Test;
try {
$test->foo();
} catch (PEAR_Exception $e) {
print $e;
}
</code>

__construct($message, $p2 = null, $p3 = null)   X-Ref
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);

param: string exception message
param: int|Exception|PEAR_Error|array|null exception cause
param: int|null exception code or null

addObserver($callback, $label = 'default')   X-Ref

param: mixed $callback  - A valid php callback, see php func is_callable()
param: string $label    The name of the observer. Use this if you want

removeObserver($label = 'default')   X-Ref
No description

getUniqueId()   X-Ref

return: int unique identifier for an observer

signal()   X-Ref
No description

getErrorData()   X-Ref
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:
<pre>
array('name' => $name, 'context' => array(...))
</pre>
return: array

getCause()   X-Ref
Returns the exception that caused this exception to be thrown

return: Exception|array The context of the exception

getCauseMessage(&$causes)   X-Ref
Function must be public to call on caused exceptions

param: array

getTraceSafe()   X-Ref
No description

getErrorClass()   X-Ref
No description

getErrorMethod()   X-Ref
No description

__toString()   X-Ref
No description

toHtml()   X-Ref
No description

toText()   X-Ref
No description