Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<Fiber::resumeFiber::getReturn>
^FiberLast updated: Mon, 26 Oct 2026

Fiber::throw

(PHP 8 >= 8.1.0)

Fiber::throw — Resumes execution of the fiber with an exception

Description

public function Fiber::throw(Throwable $exception): mixed

Resumes the fiber by throwing the given exception from the current Fiber::suspend() call.

If the fiber is not suspended when this method is called, a FiberError will be thrown.

Parameters

exception

The exception to throw into the fiber from the current Fiber::suspend() call.

Return Values

The value provided to the next call to Fiber::suspend() or null if the fiber returns. If the fiber throws an exception before suspending, it will be thrown from the call to this method.

Examples

<?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'));

?>

The above example will output something similar to:

Message of an exception thrown at the current interrupt point

<Fiber::resumeFiber::getReturn>
^FiberLast updated: Mon, 26 Oct 2026