mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
d0892f1ba9
Added complete call-seq documentation for catch/throw functionality across both Ruby and C implementations: - Class documentation: explains exception raised for unmatched throws - initialize: constructor with tag and value parameters, creates error message with proper tag inspection and stores thrown values for debugging - throw: transfers control to matching catch block with optional return value, raises UncaughtThrowError if no matching catch found, supports both single tag and tag+value forms with comprehensive usage examples - find_catcher: searches call stack for matching catch block by comparing tags using mrb_obj_eq, returns call stack index or 0 if not found - catch_syms: pre-defined symbols (Object, new, call) used by catch bytecode implementation for efficient symbol lookup - catch_iseq: bytecode instruction sequence implementing catch method logic, handles default tag creation (Object.new) and block parameter passing - catch_irep: instruction representation containing bytecode metadata for catch method execution - catch_proc: procedure object used to identify catch blocks in call stack during throw operations, marked with proper GC and scope flags - mrb_mruby_catch_gem_init: defines catch and throw as private methods in Kernel module, initializes symbols and sets up bytecode procedure - mrb_mruby_catch_gem_final: cleanup function (currently no-op as implementation uses static data structures) Co-authored-by: Atlassian Rovo Dev
30 lines
817 B
Ruby
30 lines
817 B
Ruby
#
|
|
# Exception raised when a throw is executed without a corresponding catch.
|
|
# This error contains the tag and value that were thrown.
|
|
#
|
|
class UncaughtThrowError < ArgumentError
|
|
# The tag that was thrown
|
|
attr_reader :tag
|
|
# The value that was thrown with the tag
|
|
attr_reader :value
|
|
|
|
#
|
|
# call-seq:
|
|
# UncaughtThrowError.new(tag, value) -> exception
|
|
#
|
|
# Creates a new UncaughtThrowError with the given tag and value.
|
|
# The tag is the symbol or object that was thrown, and value is
|
|
# the associated value.
|
|
#
|
|
# error = UncaughtThrowError.new(:done, "finished")
|
|
# error.tag #=> :done
|
|
# error.value #=> "finished"
|
|
# error.message #=> "uncaught throw :done"
|
|
#
|
|
def initialize(tag, value)
|
|
@tag = tag
|
|
@value = value
|
|
super("uncaught throw #{tag.inspect}")
|
|
end
|
|
end
|