Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Fiber#raise

(?::string msg) -> untyped
(::_Exception, ?::string msg, ?::Array[::string] | ::Array[::Thread::Backtrace::Location] | nil backtrace) -> untyped
fiber.raise → obj
fiber.raise(string) → obj
fiber.raise(exception [, string [, array]]) → obj

Raises an exception in the fiber at the point at which the last Fiber.yield was called. 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.

With no arguments, raises a RuntimeError. With a single String argument, raises a RuntimeError with the string as a message. Otherwise, the first parameter should be the name of an Exception class (or an object that returns an Exception object when sent an exception message). The optional second parameter sets the message associated with the exception, and the third parameter is an array of callback information. Exceptions are caught by the rescue clause of begin...end blocks.

Raises FiberError if called on a Fiber belonging to another Thread.

See Kernel#raise for more information.

See also #kill #resume #inspect #storage also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0