Hello --

On Mon, 2 Jul 2001, Yukihiro Matsumoto wrote:

> So, how about making Exception#exception clones the receiver exception
> inside, instead of creating a exception object of the receiver's class.
>
> 							matz.
>
> --- error.c	2001/06/05 07:50:59	1.28
> +++ error.c	2001/07/02 08:18:20
> @@ -324,3 +324,3 @@
>  {
> -    VALUE etype, exc;
> +    VALUE exc;
>
> @@ -328,7 +328,3 @@
>      if (argc == 1 && self == argv[0]) return self;
> -    etype = CLASS_OF(self);
> -    while (FL_TEST(etype, FL_SINGLETON)) {
> -	etype = RCLASS(etype)->super;
> -    }
> -    exc = rb_obj_alloc(etype);
> +    exc = rb_obj_clone(self);
>      rb_obj_call_init(exc, argc, argv);


That works for my little test, based on:

  class NameError
    attr_accessor :hook
  end

and then making sure hook gets propagated when anException gets
raised.

But then the question is: why clone, instead of returning self?
Meaning:

  rescue NameError => ne
    # ...
    raise ne, "message"   # would it hurt for this to raise ne,
                          # rather than a clone?

A followup question... how useful/used is Exception#exception?  Maybe
I've just been staring at it too long :-) but I'm wondering what it
does that couldn't be done already.  I notice it isn't used at all in
the distribution (plus whatever site_ruby stuff I've got):

   $ cd /usr/local/lib/ruby
   $ grep '\.exception' `find . -name *.rb -print`
   ./1.6/irb/main.rb:      @scanner.exception_on_syntax_error = false
   ./1.6/irb.rb:      @scanner.exception_on_syntax_error = false
   ./1.7/irb/main.rb:      @scanner.exception_on_syntax_error = false


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav