PEAR Progress2 logo

HTML_Progress2 : The Definitive Guide

Chapter 16. Error Handler

Table of Contents

Introduction
Configuring a Handler
Controlling error generation
Error Context Display
Custom Error Message Generation
Option: message_callback
Option: context_callback

Introduction

After many rewrites, the new error management adding to this major version of HTML_Progress2 provides again more than in branch 1.x

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 HTML_Progress2_Error object that will be return to call script (user script).

[Note] Note
In HTML_Progress 1.x each API error returns a basic PEAR_Error object.
[Tip] Tip
Easy to distinct basic PEAR_Error from other PEAR packages to HTML_Progress2 errors, even if there is a better and more robust solution: HTML_Progress2::hasErrors(). But also provide a unique way to retrieve the level of progress error (warning, error, exception) with the HTML_Progress2_Error::getLevel() method.

As usual, to check an error, you can use the PEAR error API :

  1. <?php
  2. require_once 'HTML/Progress2.php';
  3.  
  4. $meter = new HTML_Progress2();
  5.  
  6. $result = $meter->setValue('37');
  7. if (PEAR::isError($result)) {
  8.     // do something when an error is raised
  9.     $error =& $result;
  10. }
  11. ?>

as well as with :

  1. <?php
  2. require_once 'HTML/Progress2.php';
  3.  
  4. $meter = new HTML_Progress2();
  5.  
  6. $result = $meter->setValue('37');
  7. if ($meter->hasErrors() > 0) {
  8.     // do something when an error is raised
  9.     $error = $meter->getError();
  10. }
  11. ?>

which provide a portable solution, and output to screen will give something like :

Exception1: invalid input, parameter #1 "$val" was expecting "integer",
instead got "string"2 in html_progress2->setvalue (file [path_to]\[filename] on line 6)3
     
1

error level

2

message body with context informations

3

call context

Perhaps this standard behavior 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)
[Important] Important
HTML_Progress2 obey at display_errors and log_errors protocol, while HTML_Progress 1.x obey at error_reporting protocol.
HTML_Progress2 : The Definitive Guide v 2.4.0 : April 20, 2007