language/predefined/generator/throw.xml
8fee3ae9715ffa15922469eb7d98f4878917a6ee
...
...
@@ -1,6 +1,5 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-

4
3
<refentry xml:id="generator.throw" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
4
<refnamediv>
6
5
<refname>Generator::throw</refname>
...
...
@@ -9,10 +8,19 @@
9
8

10
9
<refsect1 role="description">
11
10
&reftitle.description;
12
-
<methodsynopsis>
13
-
<modifier>public</modifier> <type>void</type><methodname>Generator::throw</methodname>
14
-
<methodparam><type>Exception</type><parameter>exception</parameter></methodparam>
11
+
<methodsynopsis role="Generator">
12
+
<modifier>public</modifier> <type>mixed</type><methodname>Generator::throw</methodname>
13
+
<methodparam><type>Throwable</type><parameter>exception</parameter></methodparam>
15
14
</methodsynopsis>
15
+
<para>
16
+
Throws an exception into the generator and resumes execution of the generator.
17
+
The behavior will be the same as if the current &yield; expression was replaced with
18
+
a <literal>throw $exception</literal> statement.
19
+
</para>
20
+
<para>
21
+
If the generator is already closed when this method is invoked, the exception will
22
+
be thrown in the caller's context instead.
23
+
</para>
16
24
</refsect1>
17
25

18
26
<refsect1 role="parameters">
...
...
@@ -22,7 +30,7 @@
22
30
<term><parameter>exception</parameter></term>
23
31
<listitem>
24
32
<para>
25
-
33
+
Exception to throw into the generator.
26
34
</para>
27
35
</listitem>
28
36
</varlistentry>
...
...
@@ -36,9 +44,42 @@
36
44
</para>
37
45
</refsect1>
38
46

47
+
<refsect1 role="examples">
48
+
&reftitle.examples;
49
+
<para>
50
+
<example>
51
+
<title>Throwing an exception into a generator</title>
52
+
<programlisting role="php">
53
+
<![CDATA[
54
+
<?php
55
+
function gen() {
56
+
echo "Foo\n";
57
+
try {
58
+
yield;
59
+
} catch (Exception $e) {
60
+
echo "Exception: {$e->getMessage()}\n";
61
+
}
62
+
echo "Bar\n";
63
+
}
39
64
65
+
$gen = gen();
66
+
$gen->rewind();
67
+
$gen->throw(new Exception('Test'));
68
+
?>
69
+
]]>
70
+
</programlisting>
71
+
&example.outputs;
72
+
<screen>
73
+
<![CDATA[
74
+
Foo
75
+
Exception: Test
76
+
Bar
77
+
]]>
78
+
</screen>
79
+
</example>
80
+
</para>
81
+
</refsect1>
40
82
</refentry>
41
-

42
83
<!-- Keep this comment at the end of the file
43
84
Local variables:
44
85
mode: sgml
45
86