Examples TOCexamples

Display handler - part 2.

$Date: 2004/08/07 14:28:59 $

 Table of contents

Introduction

This example requires :


This example will show you how to handle standard html_progress api errors.

An error was volontary made on call of setAnimSpeed method (line 5). As it's an API error, default is to return error after it was raised, so only lines 7 thru 11 will be executed.

If display_errors php.ini directive is ON, result is sent to browser. But as there is no error_log handler defined in html_progress (by default), even if log_errors is ON, no action will be taken.

display_errors

Print out errors (as a part of the output). For production web sites, you're strongly encouraged to turn this feature off, and use error logging instead. Keeping display_errors enabled on a production web site may reveal security information to end users, such as file paths on your Web server, your database schema or other information.

1 <?php ini_set('display_errors', false); ?>

log_errors

Log errors into a log file (server-specific log, stderr, syslog ...) As stated above, you're strongly advised to use error logging in place of error displaying on production web sites.

1 <?php ini_set('log_errors', true); ?>

 Render options

None, all default options are used. These options are :

Legend for lineFormat: Legend for contextFormat:

[Top]

 Output

Error: invalid input, parameter #1 "$delay" was expecting "less or equal 1000", instead got "10000" in html_progress::setanimspeed (file d:\php\pear\html_progress\examples\errorstack\secure\display_errors-p2.php at line 5)

Catch PEAR_Error

[pear_error: message="invalid input, parameter #1 "$delay" was expecting "less or equal 1000", instead got "10000"" code=-100 mode=return level=error prefix="" info="Array"]

[Top]

 PHP source syntax highlight

  1. <?php
  2. require_once 'HTML/Progress.php';
  3.  
  4. $bar = new HTML_Progress();
  5. $e = $bar->setAnimSpeed(10000);   // < - - - will generate an API error
  6.  
  7. if (is_object($e)) {
  8.     if (is_a($e,'PEAR_Error')) {
  9.         die('<h1>Catch PEAR_Error</h1>'. $e->toString());
  10.     }
  11. }
  12.  
  13. if ($bar->hasErrors()) {
  14.     $err = $bar->getError();
  15.     echo '<pre>';
  16.     print_r($err);
  17.     echo '</pre>';
  18. }
  19. ?>

[Top]