| Current File : //opt/RZphp5/includes/doc/HTML_Progress2/docs/TDG/ch16.html |
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>
Chapter 16. Error Handler
</title>
<link rel="stylesheet" href="book.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.69.1" />
<link rel="start" href="index.html" title="HTML_Progress2 Manual" />
<link rel="up" href="pt04.html" title=
"Part IV. Reference Guide" />
<link rel="prev" href="ch15.html" title=
"Chapter 15. Introduction" />
<link rel="next" href="ch16s02.html" title="Configuring a Handler " />
<style type="text/css">
/*<![CDATA[*/
body {
background-color: white;
color: black;
}
:link { color: #0000FF }
:visited { color: #840084 }
:active { color: #0000FF }
div.c4 {font-family: monospace;}
div.c3 {margin-left: 0.5in; margin-right: 0.5in;}
h2.c2 {clear: both}
p.c1 {font-weight: bold}
/*]]>*/
</style>
</head>
<body>
<table class="progress2Header">
<tr>
<td>
<img src="img/pear_progress2.gif" align="left" alt=
"PEAR Progress2 logo" />
<h1>
HTML_Progress2 : The Definitive Guide
</h1>
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr>
<th colspan="3" align="center">
Chapter 16. Error Handler
</th>
</tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="ch15.html">Prev</a>
</td>
<th width="60%" align="center">
Part IV. Reference Guide
</th>
<td width="20%" align="right">
<a accesskey="n" href="ch16s02.html">Next</a>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<div class="chapter" lang="en" xml:lang="en">
<div class="titlepage">
<h2 class="title">
<a name="reference.errorhandler" id=
"reference.errorhandler"></a>Chapter 16. Error Handler
</h2>
</div>
<div class="toc">
<p class="c1">
Table of Contents
</p>
<dl>
<dt>
<span class="sect1"><a href=
"ch16.html#id4796408">Introduction</a></span>
</dt>
<dt>
<span class="sect1"><a href="ch16s02.html">Configuring a
Handler</a></span>
</dt>
<dt>
<span class="sect1"><a href="ch16s03.html">Controlling error
generation</a></span>
</dt>
<dt>
<span class="sect1"><a href="ch16s04.html">Error Context
Display</a></span>
</dt>
<dt>
<span class="sect1"><a href="ch16s05.html">Custom Error Message
Generation</a></span>
</dt>
<dd>
<dl>
<dt>
<span class="sect2"><a href="ch16s05.html#id4804100">Option:
message_callback</a></span>
</dt>
<dt>
<span class="sect2"><a href="ch16s05.html#id4804127">Option:
context_callback</a></span>
</dt>
</dl>
</dd>
</dl>
</div>
<div class="sect1" lang="en" xml:lang="en">
<div class="titlepage">
<h2 class="title c2">
<a name="id4796408" id="id4796408"></a>Introduction
</h2>
</div>
<p>
After many rewrites, the new error management adding to this major
version of HTML_Progress2 provides again more than in branch 1.x
</p>
<p>
The HTML_Progress2 package is implemented with a flexible error
handler plug-in system. You may use any error handler that you want.
Using <code class="classname">PEAR_Error</code> object (default), but
also the <code class="classname">PEAR_ErrorStack</code> package, or
any other error handler you might want to plug in.
</p>
<p>
Without any configuration, each HTML_Progress2 API error (basic or
exception) will raise a <code class=
"classname">HTML_Progress2_Error</code> object that will be return to
call script (user script).
</p>
<div class="note c3">
<table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="48">
<img alt="[Note]" src="img/admons/note.png" />
</td>
<th align="left">
Note
</th>
</tr>
<tr>
<td align="left" valign="top">
In HTML_Progress 1.x each API error returns a basic
<code class="classname">PEAR_Error</code> object.
</td>
</tr>
</table>
</div>
<div class="tip c3">
<table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="48">
<img alt="[Tip]" src="img/admons/tip.png" />
</td>
<th align="left">
Tip
</th>
</tr>
<tr>
<td align="left" valign="top">
Easy to distinct basic PEAR_Error from other PEAR packages to
HTML_Progress2 errors, even if there is a better and more
robust solution: <code class=
"methodname">HTML_Progress2::hasErrors()</code>. But also
provide a unique way to retrieve the level of progress error
(warning, error, exception) with the <code class=
"methodname">HTML_Progress2_Error::getLevel()</code> method.
</td>
</tr>
</table>
</div>
<p>
As usual, to check an error, you can use the PEAR error API :
</p>
<div class="php c4">
<ol>
<li class="li1">
<div class="de1">
<span class="kw2"><?php</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="kw1">require_once</span> <span class=
"st0">'HTML/Progress2.php'</span><span class="sy0">;</span>
</div>
</li>
<li class="li1">
<div class="de1">
</div>
</li>
<li class="li1">
<div class="de1">
<span class="re1">$meter</span> <span class="sy0">=</span>
<span class="kw2">new</span> HTML_Progress2<span class=
"br0">(</span><span class="br0">)</span><span class=
"sy0">;</span>
</div>
</li>
<li class="li1">
<div class="de1">
</div>
</li>
<li class="li1">
<div class="de1">
<span class="re1">$result</span> <span class="sy0">=</span>
<span class="re1">$meter</span><span class=
"sy0">-></span><span class="me1">setValue</span><span class=
"br0">(</span><span class="st0">'37'</span><span class=
"br0">)</span><span class="sy0">;</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="kw1">if</span> <span class=
"br0">(</span>PEAR<span class="sy0">::</span><span class=
"me2">isError</span><span class="br0">(</span><span class=
"re1">$result</span><span class="br0">)</span><span class=
"br0">)</span> <span class="br0">{</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="co1">// do something when an error
is raised</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="re1">$error</span> <span class=
"sy0">=&</span> <span class=
"re1">$result</span><span class="sy0">;</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="br0">}</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="kw2">?></span>
</div>
</li>
</ol>
</div>
<p>
as well as with :
</p>
<div class="php c4">
<ol>
<li class="li1">
<div class="de1">
<span class="kw2"><?php</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="kw1">require_once</span> <span class=
"st0">'HTML/Progress2.php'</span><span class="sy0">;</span>
</div>
</li>
<li class="li1">
<div class="de1">
</div>
</li>
<li class="li1">
<div class="de1">
<span class="re1">$meter</span> <span class="sy0">=</span>
<span class="kw2">new</span> HTML_Progress2<span class=
"br0">(</span><span class="br0">)</span><span class=
"sy0">;</span>
</div>
</li>
<li class="li1">
<div class="de1">
</div>
</li>
<li class="li1">
<div class="de1">
<span class="re1">$result</span> <span class="sy0">=</span>
<span class="re1">$meter</span><span class=
"sy0">-></span><span class="me1">setValue</span><span class=
"br0">(</span><span class="st0">'37'</span><span class=
"br0">)</span><span class="sy0">;</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="kw1">if</span> <span class=
"br0">(</span><span class="re1">$meter</span><span class=
"sy0">-></span><span class=
"me1">hasErrors</span><span class="br0">(</span><span class=
"br0">)</span> <span class="sy0">></span> <span class=
"nu0">0</span><span class="br0">)</span> <span class=
"br0">{</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="co1">// do something when an error
is raised</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="re1">$error</span> <span class=
"sy0">=</span> <span class="re1">$meter</span><span class=
"sy0">-></span><span class="me1">getError</span><span class=
"br0">(</span><span class="br0">)</span><span class=
"sy0">;</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="br0">}</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="kw2">?></span>
</div>
</li>
</ol>
</div>
<p>
which provide a portable solution, and output to screen will give
something like :
</p>
<div class="informalexample screenco">
<pre class="screen">
Exception<a name="error.1.level" id="error.1.level"></a><img src=
"img/callouts/1.gif" alt="1" border=
"0" />: invalid input, parameter #1 "$val" was expecting "integer",
instead got "string"<a name="error.1.message" id=
"error.1.message"></a><img src="img/callouts/2.gif" alt="2" border=
"0" /> in html_progress2->setvalue (file [path_to]\[filename] on line 6)<a name="error.1.context"
id="error.1.context"></a><img src="img/callouts/3.gif" alt="3" border="0" />
</pre>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td width="5%" valign="top" align="left">
<a href="#error.1.level"><img src="img/callouts/1.gif" alt=
"1" border="0" /></a>
</td>
<td valign="top" align="left">
<p>
error level
</p>
</td>
</tr>
<tr>
<td width="5%" valign="top" align="left">
<a href="#error.1.message"><img src="img/callouts/2.gif" alt=
"2" border="0" /></a>
</td>
<td valign="top" align="left">
<p>
message body with context informations
</p>
</td>
</tr>
<tr>
<td width="5%" valign="top" align="left">
<a href="#error.1.context"><img src="img/callouts/3.gif" alt=
"3" border="0" /></a>
</td>
<td valign="top" align="left">
<p>
call context
</p>
</td>
</tr>
</table>
</div>
</div>
<p>
Perhaps this standard behavior is not what you want. Don't worry, you
can change everything :
</p>
<div class="itemizedlist">
<ul type="disc">
<li>display or ignore the error
</li>
<li>display or hide part of message (error level, body, context)
</li>
</ul>
</div>
<div class="important c3">
<table border="0" summary="Important">
<tr>
<td rowspan="2" align="center" valign="top" width="48">
<img alt="[Important]" src="img/admons/important.png" />
</td>
<th align="left">
Important
</th>
</tr>
<tr>
<td align="left" valign="top">
HTML_Progress2 obey at <a class="external" href=
"http://www.php.net/manual/en/ref.errorfunc.php#ini.display-errors"
title=
"http://www.php.net/manual/en/ref.errorfunc.php#ini.display-errors">
display_errors</a> and <a class="external" href=
"http://www.php.net/manual/en/ref.errorfunc.php#ini.log-errors"
title=
"http://www.php.net/manual/en/ref.errorfunc.php#ini.log-errors">
log_errors</a> protocol, while HTML_Progress 1.x obey at
<a class="external" href=
"http://www.php.net/manual-lookup.php?pattern=error_reporting"
title=
"http://www.php.net/manual-lookup.php?pattern=error_reporting">error_reporting</a>
protocol.
</td>
</tr>
</table>
</div>
</div>
</div>
<table class="progress2Footer">
<tr>
<td align="left">
HTML_Progress2 : The Definitive Guide
</td>
<td align="right">
v 2.4.0 : April 20, 2007
</td>
</tr>
</table>
<div class="navfooter">
<hr />
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="ch15.html">Prev</a>
</td>
<td width="20%" align="center">
<a accesskey="u" href="pt04.html">Up</a>
</td>
<td width="40%" align="right">
<a accesskey="n" href="ch16s02.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">
Chapter 15. Introduction
</td>
<td width="20%" align="center">
<a accesskey="h" href="index.html">Home</a>
</td>
<td width="40%" align="right" valign="top">
Configuring a Handler
</td>
</tr>
</table>
</div>
</body>
</html>