Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Fiber#raise
(?::string msg, ?cause: ::Exception?) -> untyped
(::_Exception, ?::string msg, ?::Array[::string] | ::Array[::Thread::Backtrace::Location] | nil backtrace, ?cause: ::Exception?) -> untyped
raise(exception, message = exception.to_s, backtrace = nil, cause: $!)
raise(message = nil, cause: $!)
cont.c
View on GitHub ↗
static VALUE
rb_fiber_m_raise(int argc, VALUE *argv, VALUE self)
{
return rb_fiber_raise(self, argc, argv);
}
Raises an exception in the fiber at the point at which the last Fiber.yield was called.
Example
f = Fiber.new { puts "Before the yield" Fiber.yield 1 # -- exception will be raised here puts "After the yield" } p f.resume f.raise "Gotcha"
Output
Before the first yield 1 t.rb:8:in 'Fiber.yield': Gotcha (RuntimeError) from t.rb:8:in 'block in <main>'
If the fiber has not been started or has already run to completion, raises FiberError. If the fiber is yielding, it is resumed. If it is transferring, it is transferred into. But if it is resuming, raises FiberError.
Raises FiberError if called on a Fiber belonging to another Thread.
See Kernel#raise for more information on arguments.
Ruby version changes
-
4.0
-
Introduce support for
Fiber#raise(cause:)argument similar toKernel#raise. [Feature #21360]
-