part2-errorhandling.pkg
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PKG 代码 · 共 548 行 · 第 1/2 页
PKG
548 行
</example>
</para>
<para>
<emphasis>Lines 21 and 22</emphasis>, replace the default error handling (<emphasis>push_callback</emphasis>)
by our own function (method _pushCallback of the class HTML_Progress_TestCase_setIndeterminate).
</para>
<para>
Into our new push callback (<emphasis>lines 49 to 53</emphasis>) we informs the stack to always push error,
and never die for an exception (default behavior).
</para>
<para>
Let's have a look on the default push callback routine :
<emphasis>HTML_Progress::_handleError</emphasis>
<para>
<programlisting role="php">
<![CDATA[
<?php
function _handleError($err)
{
if ($err['level'] == 'exception') {
return HTML_PROGRESS_ERRORSTACK_LOGANDDIE;
}
}
?>
]]>
</programlisting>
</para>
</para>
<para>
On default behavior, each time an exception is raised, HTML_Progress log the error
and halt PHP script execution.
</para>
</refsect2>
</refsect1>
<refsect1 id="{@id eh-control-logging}">
<title>Controlling Error Logging</title>
<para>
The next level of control over error output is to selectively log destination. In the default
behavior <emphasis>error_handler</emphasis> callback, that is
<emphasis>HTML_Progress::_errorHandler</emphasis>, will :
<itemizedlist>
<listitem>return a PEAR_Error object (E_USER_ERROR level, with error code, message, and
context as userinfo)
</listitem>
<listitem>log error to browser screen
(if allowed by PHP INI <emphasis>display_errors</emphasis> value)
</listitem>
<listitem>log error following rules of {@link http://www.php.net/manual/en/function.error-log.php}
(if allowed by PHP INI <emphasis>log_errors</emphasis> value)
</listitem>
</itemizedlist>
</para>
<refsect2 id="{@id control-default-display}">
<title>Default Display Handler</title>
<para>
The default display handler has one parameter and two configuration options :
<para>
<table frame="all">
<tgroup cols="2">
<thead align="center">
<row>
<entry><emphasis>Parameter</emphasis></entry>
<entry><emphasis>Default value</emphasis></entry>
</row>
</thead>
<tbody>
<row>
<entry><emphasis>conf</emphasis></entry>
<entry>see array below </entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
<table frame="all">
<tgroup cols="3">
<thead align="center">
<row>
<entry><emphasis>Option</emphasis></entry>
<entry><emphasis>Default value</emphasis></entry>
</row>
</thead>
<tbody>
<row>
<entry><emphasis>lineFormat</emphasis></entry>
<entry>'<b>%1$s</b>: %2$s %3$s' </entry>
</row>
<row>
<entry><emphasis>contextFormat</emphasis></entry>
<entry>' in <b>%3$s</b> (file <b>%1$s</b> at line <b>%2$s</b>)' </entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
with <emphasis>lineFormat</emphasis> parameters:
<itemizedlist>
<listitem>1$ = error level </listitem>
<listitem>2$ = error message </listitem>
<listitem>3$ = context line formatted </listitem>
</itemizedlist>
</para>
<para>
with <emphasis>contextFormat</emphasis> parameters:
<itemizedlist>
<listitem>$1 = filename </listitem>
<listitem>$2 = line in file </listitem>
<listitem>$3 = class call-type function </listitem>
</itemizedlist>
See {@link http://www.php.net/manual/en/function.debug-backtrace.php} for call-type details.
</para>
</para>
</refsect2>
<refsect2 id="{@id control-default-errorlog}">
<title>Default Error_Log Handler</title>
<para>
The default error_log handler has three parameters and five configuration options :
<para>
<table frame="all">
<tgroup cols="2">
<thead align="center">
<row>
<entry><emphasis>Parameter</emphasis></entry>
<entry><emphasis>Default value</emphasis></entry>
</row>
</thead>
<tbody>
<row>
<entry><emphasis>name</emphasis></entry>
<entry> </entry>
</row>
<row>
<entry><emphasis>ident</emphasis></entry>
<entry> </entry>
</row>
<row>
<entry><emphasis>conf</emphasis></entry>
<entry>see array below </entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
with <emphasis>name</emphasis> parameter:
<itemizedlist>
<listitem><emphasis>HTML_PROGRESS_LOG_TYPE_SYSTEM</emphasis>
message is sent to PHP's system logger, using the Operating System's system logging mechanism
or a file, depending on what the error_log configuration directive (PHP INI) is set to.
</listitem>
<listitem><emphasis>HTML_PROGRESS_LOG_TYPE_MAIL</emphasis>
message is sent by email to the address in the destination parameter.
This is the only message type where the fourth parameter, extra_headers is used.
This message type uses the same internal function as mail() does.
</listitem>
<listitem><emphasis>HTML_PROGRESS_LOG_TYPE_FILE</emphasis>
message is appended to the file destination.
</listitem>
</itemizedlist>
</para>
<para>
<table frame="all">
<tgroup cols="2">
<thead align="center">
<row>
<entry><emphasis>Option</emphasis></entry>
<entry><emphasis>Default value</emphasis></entry>
</row>
</thead>
<tbody>
<row>
<entry><emphasis>destination</emphasis></entry>
<entry> </entry>
</row>
<row>
<entry><emphasis>extra_headers</emphasis></entry>
<entry> </entry>
</row>
<row>
<entry><emphasis>lineFormat</emphasis></entry>
<entry>'%1$s %2$s [%3$s] %4$s %5$s' </entry>
</row>
<row>
<entry><emphasis>timeFormat</emphasis></entry>
<entry>'%b %d %H:%M:%S' </entry>
</row>
<row>
<entry><emphasis>contextFormat</emphasis></entry>
<entry>' in %3$s (file %1$s at line %2$s)' </entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
with <emphasis>lineFormat</emphasis> parameter:
<itemizedlist>
<listitem>1$ = error time from time line formatted </listitem>
<listitem>2$ = error handler ident </listitem>
<listitem>3$ = error level </listitem>
<listitem>4$ = error message </listitem>
<listitem>5$ = context line formatted </listitem>
</itemizedlist>
</para>
<para>
with <emphasis>timeFormat</emphasis> parameter:
<itemizedlist>
<listitem>see {@link http://www.php.net/manual/en/function.strftime.php} </listitem>
</itemizedlist>
</para>
<para>
with <emphasis>contextFormat</emphasis> parameter:
<itemizedlist>
<listitem>$1 = filename </listitem>
<listitem>$2 = line in file </listitem>
<listitem>$3 = class call-type function </listitem>
</itemizedlist>
See {@link http://www.php.net/manual/en/function.debug-backtrace.php} for call-type details.
</para>
</para>
</refsect2>
</refsect1>
<refsect1 id="{@id eh-ultimate-control}">
<title>Ultimate control: Custom Error Handlers</title>
<para>
For most of users, the basic and default HTML_Progress error handling system will be enough.
But if you want more efficiency, you should set a custom error handler.
Let's take an example and follow it to see how to do :
</para>
<example>
{@example display_errors-p6.php}
</example>
<para>
<emphasis>Lines 4 to 10</emphasis> we defined our 'push_callback' routine
to ignore all exception error.
</para>
<para>
<emphasis>Lines 11 to 29</emphasis> we defined our custom 'error_handler' routine.
</para>
<para>
<emphasis>Line 39</emphasis>, only the display handler is defined with configuration options
'lineFormat' and 'contextFormat'.
</para>
<para>
<emphasis>Line 41</emphasis>, we informs the new instance of HTML_Progress
to use this custom error handler.
</para>
<para>
<emphasis>Line 42</emphasis>, raise an exception that is ignored and code line 44 thru 55
do nothing.
Next (<emphasis>line 57</emphasis>) raise a basic error that return NULL.
So lines 59 to 63 are ignored, and only lines 64 to 67 do their job.
</para>
<para>
Finally result of this process give on web standard output (browser) :
<screen>
<emphasis>Error</emphasis>: invalid input, parameter #1 "$delay" was expecting "less or equal 1000", instead got "10000"
---------------------------------------------------------------------------------------------------
<emphasis>Function</emphasis>: html_progress->setanimspeed
<emphasis>File</emphasis>: d:\php\pear\html_progress\tutorials\html_progress\examples\display_errors-p6.php
<emphasis>Line</emphasis>: 57
<emphasis>Catch HTML_Progress error</emphasis>
invalid input, parameter #1 "$delay" was expecting "less or equal 1000", instead got "10000"
</screen>
</para>
</refsect1>
</refentry>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?