This example will show you how to cutomize HTML_Progress2 error handling with standard PEAR_Error object.
Exceptions will be catched and script won't die anymore, so line 82 will be reached !
error_message_prefix =
mode = 16
level = 1024
code = -100
message = invalid input, parameter #3 "$min" was expecting "integer", instead got "string"
Error:
invalid input, parameter #1 "$min" was expecting "positive", instead got "-1"
File: [path_to]\errorcustom.php
Line: 77
Function: html_progress2->setminimum
Exception:
invalid input, parameter #1 "$continuous" was expecting "boolean", instead got "string"
File: [path_to]\errorcustom.php
Line: 80
Function: html_progress2->setindeterminate
still alive !
For security reasons live demo is not available and i've replaced the real path to file errorcustom.php by [path_to]. But in real conditions, you will see it!
This example requires mandatory resources :
On example A, all errors will be proceed by the user callback myErrorCallback (line 53), function declared on lines 23-31.
This function print only some PEAR_Error object properties.
To catch exception and avoid script to halt (default behaviour), the push_callback option (line 55) set function my1ErrorHandler declared on lines 33-36. This function will returns NULL value, that means PEAR_Error object follows the PEAR::setErrorHandling directive.
Option | Value | Default |
---|---|---|
push_callback | my1ErrorHandler | HTML_Progress2_Error::_handleError |
On example B, all errors will be proceed by the default error callback (HTML_Progress2::_errorHandler) that always raised a PEAR_Error object with mode returns by the push_callback user function (a valid PEAR_ERROR_* constant).
In our case, the push_callback option set function my2ErrorHandler
(line 70), declared on lines 38-41.
This function will returns PEAR_ERROR_CALLBACK to force HTML_Progress2
error handler to use the HTML_Progress2_Error::log method.
This method will send error message on browser and/or on log file, depending on the php.ini directives
value display_errors, log_errors.
To be sure to have something on display and in the default 'html_progress_error.log' file, php.ini directives were set to On (lines 47-48).
As we also want to beautify display render, we changed the default display driver options (lines 63-68) activated on line 71.
Option | Value | Default |
---|---|---|
push_callback | my2ErrorHandler | HTML_Progress2_Error::_handleError |
handler | display = array([1]) | display = array([2]) |
Custom options of display handler:
display [1] | Value |
---|---|
lineFormat | <b>%1\$s</b>: %2\$s<br/>%3\$s<hr/> |
contextFormat |
<b>File:</b> %1\$s <br /> <b>Line:</b> %2\$s <br /> <b>Function:</b> %3\$s |
Default options of display handler:
display [2] | Value |
---|---|
eol | <br/>\\n |
lineFormat | <b>%1\$s</b>: %2\$s %3\$s |
contextFormat | in <b>%3\$s</b> (file <b>%1\$s</b> on line <b>%2\$s</b>) |