What should be the result of calling x.exception(Exception arg) and x.exception(Class arg) then? Currently both create a new exception of type x.classith message arg (unless arg == x).

1) Passing a class:

irb(main):001:0> a = Exception.new
=> #<Exception: Exception>
irb(main):002:0> b = a.exception(IOError)
=> #<Exception: #<Exception:0x3127bc4>>
irb(main):003:0> b.message
=> IOError
irb(main):004:0> b.message.class
=> Class

2) Passing an exception instance:

irb(main):001:0> a = Exception.new
=> #<Exception: Exception>
irb(main):002:0> b = a.exception(IOError.new)
=> #<Exception: #<Exception:0x33e701c>>              
irb(main):003:0> b.message
=> #<IOError: IOError>     

3) Passing a string:

irb(main):001:0> a = Exception.new
=> #<Exception: Exception>
irb(main):002:0> b = a.exception("some message")
=> #<Exception: some message>
irb(main):003:0> b.message
=> "some message"

Hence "arg is a message only when arg is a string" is not true for the current implementation.
I'm not saying that cases 1) and 2) are wrong. There are correct in some sense (unless message is intended to always be a string). The case that's definitely broken is

4) 
irb(main):001:0> a = Exception.new
=> #<Exception: Exception>
irb(main):002:0> a.exception(a)
=> #<Exception: Exception>

Tomas

-----Original Message-----
From: Yukihiro Matsumoto [mailto:matz / ruby-lang.org] 
Sent: Friday, March 06, 2009 12:44 AM
To: ruby-core / ruby-lang.org
Subject: [ruby-core:22699] Re: [Bug #1248] e.exception(e) returns self

Hi,

In message "Re: [ruby-core:22698] Re: [Bug #1248] e.exception(e) returns self"
    on Fri, 6 Mar 2009 16:52:47 +0900, Tomas Matousek <Tomas.Matousek / microsoft.com> writes:

|Well the reason is that arg is supposed to be a message, right? A message can be an arbitrary object. So if I pass e as a message, why it doesn't become a value of the message property?

The arg is supposed to be an exception, or exception class, or a
message, which means arg is a message only when arg is a string.  The
whole purpose of exception method is to duck-type raise semantics,
that is

  raise ExceptionClass   # specifying exception class

to make a new exception, and

  raise anException      # specifying exception object

to re-raise the exception.

							matz.