Project

General

Profile

This project is closed and read-only.

Actions

Bug #1886

closed

Strange exception thrown when Exception#new is overridden and returns a non-Exception

Bug #1886: Strange exception thrown when Exception#new is overridden and returns a non-Exception

Added by tmat (Tomas Matousek) about 17 years ago. Updated over 15 years ago.

Status:
Closed
ruby -v:
ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mswin32]
[ruby-core:24767]

Description

=begin
class ZeroDivisionError
def self.new(message)
puts 'new ZeroDivError'
'not an exception'
end
end

module Any
def self.===(other)
puts "?#{other.inspect}"
true
end
end

begin
1/0
rescue Exception, Any
puts "rescue"
p $!
ensure
puts "ensure"
end

puts 'Done'

=====

The output is:
new ZeroDivError
ensure

This means that if a non-Exception is returned from the new method above, the stack is magically unwound ignoring all rescue clauses (=== is not called) and no error message is displayed at all.

The same behavior can be observed in both:
ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mswin32]
=end


Related issues 1 (0 open1 closed)

Related to Ruby - Feature #12338: bypass Exception.newClosedActions

Updated by nobu (Nobuyoshi Nakada) about 17 years ago Actions #1

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r24403.
=end

Updated by shyouhei (Shyouhei Urabe) about 17 years ago Actions #2

  • Status changed from Closed to Assigned
  • Assignee set to wyhaines (Kirk Haines)

=begin

=end

Updated by wyhaines (Kirk Haines) about 16 years ago Actions #3

  • Status changed from Assigned to Closed

=begin
This issue was solved with changeset r28374.
Tomas, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Updated by nobu (Nobuyoshi Nakada) over 10 years ago Actions #4

Actions

Also available in: PDF Atom