Skip to content

throw.xml Add an example #4514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions language/predefined/fiber/throw.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,43 @@
</para>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>Fiber::throw</function> example</title>
<programlisting role="php">
<![CDATA[
<?php

$fiber = new Fiber(function () {
try {
// Suspend execution of the fiber declaring an interruption point
Fiber::suspend();
} catch (Throwable $e) {
echo $e->getMessage();
}
});

$fiber->start();

// Resumes execution of the fiber with
// passing the Exception to throw at the interruption point
$fiber->throw(new Exception('Message of an exception thrown at the current interrupt point'));

?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Message of an exception thrown at the current interrupt point
]]>
</screen>
</example>
</para>
</refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
Expand Down