Project

General

Profile

Actions

Feature #9400

open

Respect constant lookup when using `raise`

Added by wardrop (Tom Wardrop) almost 11 years ago. Updated over 5 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:<unknown>]

Description

When raising an error without defining an exception class, ::RuntimeError appears to be a hard-coded default. I propose that this be changed so proper constant lookup rules are respected when looking up RuntimeError. For example, I would expect both of the raise calls in this example to be identical and use the redefined RuntimeError class with the hello method:

module Test
  class RuntimeError < RuntimeError
    def hello
      puts 'Hi there!'
    end
  end

  begin
    raise RuntimeError
  rescue => e
    e.hello #=> Hi there!
  end

  begin
    raise
  rescue => e
    e.hello #=> undefined method `hello' for RuntimeError:RuntimeError
  end
end

I would find this behavior to be of quite some convenience. A lot (most?) libraries only have a single error class, and this would allow developers to implicitly raise exceptions of the appropriate class.

Thoughts?

Actions #1

Updated by jeremyevans0 (Jeremy Evans) over 5 years ago

  • Tracker changed from Bug to Feature
  • ruby -v deleted (2.1.0)
  • Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN)
Actions

Also available in: Atom PDF

Like0
Like0