From: David Alan Black Date: 2001-06-29T07:31:14+09:00 Subject: [ruby-talk:17037] keeping an Exception object alive Hello -- This started out as an attempt to answer ruby-talk:17010, but it has taken on a life of its own :-) I wanted to use a particular exception object as the first argument to raise, in order to keep that particular object alive: def etest [].implode # trigger NameError rescue NameError => ne p ne.id raise ne end begin etest rescue NameError => ne p ne.id end => 537630972 537630972 Then I wanted to add a message, so I made this change: - raise ne + raise ne, "some message" This time I got different objects: => 537630942 537630872 OK... so a new NameError object is being created, based on the class of ne. A workaround is possible, if one really wants to keep the same object alive: rescue NameError => ne ne = ne.exception("some message") p ne.id raise ne but there's a bit of a POLS issue here, at least for me. (It's all working as documented -- it's the way it works that provides the S :-) What I'm left wondering is why there's no Exception#message= method, which could be used directly and/or perhaps in the background of Exception#exception. (So that 'raise ne, "message"' would raise ne itself, first changing its message, rather than creating a new object.) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav