Issue #6372 has been updated by trans (Thomas Sawyer).


=begin
Is your objection to `#thrown?`. If so, that's not the feature request. It is just an example of usage. Consider this example instead from MiniTest:

    ##
    # Fails unless the block throws +sym+

    def assert_throws sym, msg = nil
      default = "Expected #{mu_pp(sym)} to have been thrown"
      caught = true
      catch(sym) do
        begin
          yield
        rescue ThreadError => e       # wtf?!? 1.8 + threads == suck
          default += ", not :#{e.message[/uncaught throw \`(\w+?)\'/, 1]}"
        rescue ArgumentError => e     # 1.9 exception
          default += ", not #{e.message.split(/ /).last}"
        rescue NameError => e         # 1.8 exception
          default += ", not #{e.name.inspect}"
        end
        caught = false
      end

      assert caught, message(msg) { default }
    end

This code suffers the same problem. It is not a reliable test of throw b/c other errors can be NameError or ArgumentError. Sp how do we reliably test a throw?
=end

----------------------------------------
Feature #6372: More specific error for uncaught throw
https://bugs.ruby-lang.org/issues/6372#change-31816

Author: trans (Thomas Sawyer)
Status: Rejected
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0


I have this method:

=begin
  class Symbol
    # Does the block throw the symbol?
    # 
    def thrown?
      catch(self) do
        begin
          yield
          true
        rescue ArgumentError => err     # 1.9 exception
          false
        rescue NameError => err         # 1.8 exception
          false
        end
      end
    end
  end
=end

But it was recently pointed out to me that the rescue of ArgumentError and NameError is not good enough b/c they might rescue an unrelated error of the same type. So to make this right there needs to be a more specific error. Perhaps `class ThrowError < ArgumentError`.



-- 
http://bugs.ruby-lang.org/