HTML_Progress::hasErrors
returns count of API error
Synopsisrequire_once 'HTML/Progress.php';
integer HTML_Progress::hasErrors()
DescriptionThis method tell whether there are errors into HTML_Progress stack, and how much.
Note( HTML_Progress >= 1.2.0RC3 )
 | This function can be called statically. |
 | The HTML_Progress error stack follows the same PEAR_ErrorStack structure: associative array
with keys 'code', 'params', 'package', 'level', 'time', 'context'. |
SeeHTML_Progress::raiseError,
HTML_Progress::getError
ExampleExample below will produce a such output on browser:
Error: invalid input, parameter #1 "$delay" was expecting "less or equal 1000", instead got "10000"
---------------------------------------------------------------------------------------------------
Function: html_progress::setanimspeed
File: d:\php\pear\html_progress\tutorials\html_progress\examples\display_errors-p6.php
Line: 55
Catch HTML_Progress error
invalid input, parameter #1 "$delay" was expecting "less or equal 1000", instead got "10000"
- <?php
- require_once 'HTML/Progress.php';
-
- function _pushCallback($err)
- {
- // now don't die if the error is an exception, it will be ignored
- if ($err['level'] == 'exception') {
- return HTML_PROGRESS_ERRORSTACK_IGNORE;
- }
- }
- function _errorHandler($err)
- {
- global $options;
-
- $display_errors = ini_get('display_errors');
-
- if ($display_errors) {
- $lineFormat = $options['lineFormat'];
- $contextFormat = $options['contextFormat'];
-
- $file = $err['context']['file'];
- $line = $err['context']['line'];
- $func = $err['context']['class'];
- $func .= $err['context']['type'];
- $func .= $err['context']['function'];
-
- $context = sprintf($contextFormat, $file, $line, $func);
-
- printf($lineFormat."<br />\n", ucfirst($err['level']), $err['message'], $context);
- }
- }
- $logger['push_callback'] = '_pushCallback';
- $logger['error_handler'] = '_errorHandler';
-
- $options = array(
- 'lineFormat' => '<b>%1$s</b>: %2$s <hr>%3$s',
- 'contextFormat' => '<b>Function</b>: %3$s<br/><b>File</b>: %1$s<br/><b>Line</b>: %2$s'
- );
- $logger['handler']['display'] = array('conf' => $options);
-
- $bar = new HTML_Progress($logger);
- $e = $bar->setAnimSpeed('100'); // < - - - will generate an API exception
-
- if (is_object($e)) {
- if (is_a($e,'PEAR_Error')) {
- die('<h1>Catch PEAR_Error API exception</h1>'. $e->toString());
- }
- }
- if (HTML_Progress::hasErrors()) {
- $err = HTML_Progress::getError();
- echo '<pre>';
- print_r($err);
- echo '</pre>';
- die('<h1>Catch HTML_Progress exception</h1>');
- }
-
- $e = $bar->setAnimSpeed(10000); // < - - - will generate an API error
-
- if (is_object($e)) {
- if (is_a($e,'PEAR_Error')) {
- die('<h1>Catch PEAR_Error API error</h1>'. $e->toString());
- }
- }
- if (HTML_Progress::hasErrors()) {
- $err = HTML_Progress::getError();
- die('<h1>Catch HTML_Progress error</h1>'.$err['message']);
- }
- ?>
Prev |
Up |
Next |
HTML_Progress::raiseError |
Reference Guide |
HTML_Progress::getError |
|
|