<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.fiber.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'fiber.throw.php',
    1 => 'Fiber::throw',
    2 => 'Resumes execution of the fiber with an exception',
  ),
  'up' => 
  array (
    0 => 'class.fiber.php',
    1 => 'Fiber',
  ),
  'prev' => 
  array (
    0 => 'fiber.resume.php',
    1 => 'Fiber::resume',
  ),
  'next' => 
  array (
    0 => 'fiber.getreturn.php',
    1 => 'Fiber::getReturn',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'language/predefined/fiber/throw.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="fiber.throw" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Fiber::throw</h1>
  <p class="verinfo">(PHP 8 &gt;= 8.1.0)</p><p class="refpurpose"><span class="refname">Fiber::throw</span> &mdash; <span class="dc-title">Resumes execution of the fiber with an exception</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-fiber.throw-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">function</span> <span class="methodname"><strong>Fiber::throw</strong></span>(<span class="methodparam"><span class="type"><a href="class.throwable.php" class="type Throwable">Throwable</a></span> <code class="parameter">$exception</code></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
   Resumes the fiber by throwing the given exception from the current <span class="methodname"><a href="fiber.suspend.php" class="methodname">Fiber::suspend()</a></span> call.
  </p>
  <p class="para">
   If the fiber is not suspended when this method is called, a <span class="classname"><a href="class.fibererror.php" class="classname">FiberError</a></span> will be thrown.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-fiber.throw-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">exception</code></dt>
    <dd>
     <p class="para">
      The exception to throw into the fiber from the current <span class="methodname"><a href="fiber.suspend.php" class="methodname">Fiber::suspend()</a></span> call.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-fiber.throw-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   The value provided to the next call to <span class="methodname"><a href="fiber.suspend.php" class="methodname">Fiber::suspend()</a></span> or <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> if the fiber returns.
   If the fiber throws an exception before suspending, it will be thrown from the call to this method.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-fiber.throw-examples">
  <h3 class="title">Examples</h3>
  <div class="informalexample">
   <div class="example-contents">
<div class="annotation-non-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$fiber </span><span style="color: #007700">= new </span><span style="color: #0000BB">Fiber</span><span style="color: #007700">(function () {<br />   try {<br />       </span><span style="color: #FF8000">// Suspend execution of the fiber declaring an interruption point<br />       </span><span style="color: #0000BB">Fiber</span><span style="color: #007700">::</span><span style="color: #0000BB">suspend</span><span style="color: #007700">();<br />   } catch (</span><span style="color: #0000BB">Throwable $e</span><span style="color: #007700">) {<br />       echo </span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">();<br />   }<br />});<br /><br /></span><span style="color: #0000BB">$fiber</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">start</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// Resumes execution of the fiber with<br />// passing the Exception to throw at the interruption point<br /></span><span style="color: #0000BB">$fiber</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">throw</span><span style="color: #007700">(new </span><span style="color: #0000BB">Exception</span><span style="color: #007700">(</span><span style="color: #DD0000">'Message of an exception thrown at the current interrupt point'</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <p class="simpara">The above example will output
something similar to:</p>
   <div class="example-contents screen">
<div class="annotation-non-interactive examplescode"><pre class="examplescode">Message of an exception thrown at the current interrupt point</pre>
</div>
   </div>
  </div>
 </div>


</div><?php manual_footer($setup); ?>