Ignore

Overview

This example will show you how to ignore HTML_Progress2 errors but keep them in stack.

Exceptions will be ignored as all other errors, so line 49 will be reached !

As you can see on browser screen, error are kept in stack with informations (code, level, params) and it's up to you to choose to display them or not (lines 40-47).

Screenshot

3 errors has occured

error #1
Array ( [code] => -100 [level] => exception [params] => Array ( [var] => $min [was] => string [expected] => integer [paramnum] => 3 ) )


error #2
Array ( [code] => -100 [level] => error [params] => Array ( [var] => $min [was] => -1 [expected] => positive [paramnum] => 1 ) )


error #3
Array ( [code] => -100 [level] => exception [params] => Array ( [var] => $continuous [was] => string [expected] => boolean [paramnum] => 1 ) )


still alive !

Demonstration

warning For security reasons live demo is not available

Dependencies

This example requires mandatory resources :

Explains step by step

On example A, all errors will be proceed by the user error handler defined by option error_handler (line 28). This function myErrorHandler declared on lines 21-24, returns NULL value because we have decided to ignore all errors and do nothing.

Option Value Default
error_handler myErrorHandler HTML_Progress2::_errorHandler

Default behaviour is to kept errors in stack, and especially basic informations (code, level, params) if the error_handler function returns NULL.

Source Code

  1. <?php
  2. /**
  3. * Simply ignores html_progress2 errors that occurs
  4. * with PEAR_Error handler.
  5. *
  6. * @version    $Id: errorignore.php,v 1.1 2005/06/12 21:03:04 farell Exp $
  7. * @author     Laurent Laville <pear@laurent-laville.org>
  8. * @package    HTML_Progress2
  9. * @subpackage Examples
  10. * @access     public
  11. */
  12. require_once 'HTML/Progress2.php';
  13.  
  14. function dump($title, $e)
  15. {
  16.     echo "<h2> $title </h2>";
  17.     print_r($e);
  18.     echo '<hr/>';
  19. }
  20.  
  21. function myErrorHandler()
  22. {
  23.     return null;
  24. }
  25.  
  26. // Example A. ---------------------------------------------
  27.  
  28. $prefs = array('error_handler' => 'myErrorHandler');
  29.  
  30. // A1. Exception
  31. $pb1 = new HTML_Progress2($prefs, HTML_PROGRESS2_BAR_VERTICAL, '0', 130);
  32.  
  33. // A2. Error
  34. $pb1->setMinimum(-1);
  35.  
  36. // A3. Exception
  37. $pb1->setIndeterminate('true');
  38.  
  39.  
  40. $countErrors = $pb1->hasErrors();
  41. if ($countErrors > 0) {
  42.     echo "<h1>$countErrors errors has occured </h1>";
  43.     for ($i=0; $i<$countErrors; $i++) {
  44.         $e = $pb1->getError();
  45.         dump('error #'.($i+1), $e);
  46.     }
  47. }
  48.  
  49. print 'still alive !'
  50.  
  51. ?>