-
Notifications
You must be signed in to change notification settings - Fork 104
/
trigger-error.xml
150 lines (142 loc) · 4.28 KB
/
trigger-error.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: d715365c098db000eaf7dcd987ee6093f6e83091 Maintainer: daijie Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.trigger-error" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>trigger_error</refname>
<refpurpose>产生一个用户级别的 error/warning/notice 信息</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>true</type><methodname>trigger_error</methodname>
<methodparam><type>string</type><parameter>message</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>error_level</parameter><initializer><constant>E_USER_NOTICE</constant></initializer></methodparam>
</methodsynopsis>
<para>
用于触发一个用户级别的错误条件,它能结合内置的错误处理器所关联,或者可以使用用户定义的函数作为新的错误处理程序(<function>set_error_handler</function>)。
</para>
<para>
该函数在你运行出现异常时,需要产生一个特定的响应时非常有用。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>message</parameter></term>
<listitem>
<para>
该 error 的特定错误信息,长度限制在了 1024 个字节。超过 1024 字节的字符都会被截断。
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>error_level</parameter></term>
<listitem>
<para>
该 error 所特定的错误类型。仅 E_USER 系列常量对其有效,默认是 <constant>E_USER_NOTICE</constant>。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.true.always;
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
如果 <parameter>error_level</parameter> 不是 <constant>E_USER_ERROR</constant>、<constant>E_USER_WARNING</constant>、<constant>E_USER_NOTICE</constant>
或 <constant>E_USER_DEPRECATED</constant>,此函数将抛出 <classname>ValueError</classname>。
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.0.0</entry>
<entry>
如果指定 <parameter>error_level</parameter> 无效,此函数现在将抛出 <classname>ValueError</classname>。之前返回 &false;。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>trigger_error</function> 示例</title>
<para>
<function>set_error_handler</function> 可见到更多详细的例子。
</para>
<programlisting role="php">
<![CDATA[
<?php
if ($divisor == 0) {
trigger_error("Cannot divide by zero", E_USER_ERROR);
}
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<warning>
<para>
在 <parameter>message</parameter>
里的 HTML 实体,并不会被转义。如果错误消息要显示在浏览器里,需要对错误消息使用
<function>htmlentities</function>。
</para>
</warning>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>error_reporting</function></member>
<member><function>set_error_handler</function></member>
<member><function>restore_error_handler</function></member>
<member><link linkend="errorfunc.constants">错误级别常量</link></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->