****************************
The HTML_Progress2 Package
****************************
-------------------------------------
User Documentation - Error Handling
-------------------------------------
:Author: Laurent Laville
:Contact: pear@laurent-laville.org
:Date: $Date: 2005/06/15 06:57:31 $
:Revision: $Revision: 1.2 $
Using error Handler
======================
The HTML_Progress2 package is implemented with a flexible error handler
plug-in system. You may use any error handler that you want. Using PEAR_Error
object (default), but also the PEAR_ErrorStack package, or any other error
handler you might want to plug in.
Without any configuration, each HTML_Progress2 API error (basic or exception)
will raise a PEAR_Error instance that will be return to call script (user
script).
As usual you can use the PEAR error API as well:
....
::
require_once 'HTML/Progress2.php';
$meter = new HTML_Progress2();
$result = $meter->setValue('37');
if (PEAR::isError($result)) {
// do something when an error is raised
}
....
Output will look like:
Exception: invalid input, parameter #1 "$val" was expecting "integer",
instead got "string" in html_progress2->setvalue (file
[...path_to...]\eh.php on line 6)
You can notice the following:
- the error level:
Exception
- the message body with context informations:
invalid input, parameter #1 "$val" was expecting "integer", instead got
"string"
- the context of call:
in html_progress2->setvalue (file [...path_to...]\eh.php on line 6)
Perhaps this standard behaviour is not what you want. Don't worry, you can
change everything :
- display or ignore the error
- display or hide part of message (error level, body, context)
Configuring a Handler
---------------------
A error handler's configuration is determined by the arguments used in its
construction. Here's an overview of these parameters.
....
::
require_once 'HTML/Progress2.php';
$errorConf = array('error_handler' => 'myErrorHandler',
'push_callback' => 'myError',
// ... more options
);
$meter = new HTML_Progress2($errorConf);
....
+--------------------+-----------+-------------------------------------------+
| Option | Type | Description |
+====================+===========+===========================================+
| `error_handler` | callback | A valid callback (function) to manage |
| | | errors raised by the |
| | | HTML_Progress2::raiseError() method. |
| | | Default is: HTML_Progress2::_errorHandler |
+--------------------+-----------+-------------------------------------------+
| `push_callback` | callback | A valid callback (function) that decides |
| | | to following action. |
| | | Default return: PEAR_ERROR_DIE if |
| | | exception |
| | | NULL otherwise |
+--------------------+-----------+-------------------------------------------+
| `message_callback` | callback | A valid callback (function) to control |
| | | message generation. |
| | | Default is: |
| | | HTML_Progress2_Error::_msgCallback. |
+--------------------+-----------+-------------------------------------------+
| `context_callback` | callback | A valid callback (function) to control |
| | | error context generation. |
| | | Default is: |
| | | HTML_Progress2_Error::getBacktrace. |
+--------------------+-----------+-------------------------------------------+
Controlling error generation
----------------------------
There are many scenarios in which fine-grained control over error raising is
absolutely necessary.
If you want to ignore all errors raised (no display, no logs) and avoid to
include PEAR core class, then :
....
::
function myErrorHandler()
{
return null;
}
require_once 'HTML/Progress2.php';
$errorConf = array('error_handler' => 'myErrorHandler');
$meter = new HTML_Progress2($errorConf);
....
Option : `push_callback`
The default error handling callback means that first exception will kill the
script (returns PEAR_ERROR_DIE constant) and all other error levels will
allow the script to continue normally (returns NULL).
Error Context Display
---------------------
In some cases, you may want to customize error generation. For instance,
for each error (basic/exception), it is useful to include file, line number,
and class/function context information in order to trace it. The default
option will be sufficient for most cases but you want perhaps customize the
output format (render) of context information.
You can change default render options with something like :
....
::
$displayConfig = array(
'lineFormat' => '%1$s: %2$s
%3$s