What should be the result of calling x.exception(Exception arg) and x.excep=
tion(Class arg) then? Currently both create a new exception of type x.class=
 with message arg (unless arg =3D=3D x).

1) Passing a class:

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

2) Passing an exception instance:

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

3) Passing a string:

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

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

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

Tomas

-----Original Message-----
From: Yukihiro Matsumoto [mailto:matz / ruby-lang.org]=20
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 se=
lf"
    on Fri, 6 Mar 2009 16:52:47 +0900, Tomas Matousek <Tomas.Matousek@micro=
soft.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 bec=
ome 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.