Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9258683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:28:11+00:00 2026-06-18T12:28:11+00:00

class Test def foo throw(:label, foo) should never get here end def bar bar

  • 0
class Test
  def foo
    throw(:label, foo)
    "should never get here"
  end

  def bar
    "bar"
  end
end

test = Test.new

Now I tried the below:

puts("bar -> " + catch(:label) {test.bar})

and got :

bar -> bar
=> nil

Now when I tried:

puts("foo -> " + catch(:label) {test.foo})

I expected that i would get nil but actually got the below:

SystemStackError: stack level too deep
    from /usr/lib/ruby/1.9.1/irb/workspace.rb:80
Maybe IRB bug!

I am unable to explain myself why this. Could anyone help me for the same?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:28:13+00:00Added an answer on June 18, 2026 at 12:28 pm

    The infinite loop happens outside the throw/catch.

    def foo
      throw(:label, foo) # <-
      "should never get here"
    end
    

    The value returned has to be generated first, no lazy eval there. So
    it calls foo again, and you have your infinite recursion without any
    stopping point. If you want nil, use

    def foo
      throw(:label, nil) # <-
      "should never get here"
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

require 'rubygems' require 'test/unit' class Thing attr_accessor :foo def set_stuff @foo = 'bar' end
Here's an example of my problem : class bar() : spam = foo() def
Can one write something like: class Test(object): def _decorator(self, foo): foo() @self._decorator def bar(self):
I get this error object has no attribute 'im_func' with this class Test(object): def
module Test def self.model_method puts this is a module method end end class A
Here is what my code looks like: module A def foo puts A end
Example: require 'commandline' class App < CommandLine::Application def initialize end def main raise 'foo'
I have codes just like follows: class test: def do_something(): pass test1 = test()
The following code: class MyClass(): def test(self): self.__x = 0 def __setattr__(self, name, value):
Say I have code like this: class Car def test_drive!; end end class AssemblyLine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.