I have been working on the Perl 5 reference implementation of
RFC 88 functionality (Try.pm, which is currently available at:
http://www.avrasoft.com/perl6/try6-ref5.txt ), and I stumbled
across the following result.

If you are writing some code, and there is a "throw" subroutine
in scope, and there is a package Exception in scope and it has
a "throw" subroutine, then Perl 5 can tell the following apart
(search for the /!throw-3/ regression test in try6-ref5.txt):

    throw "A Message";      # Calls the subroutine.

    throw  Exception;       # Calls the method.

    throw "A Foo Message",  tag => "ABC.1234";

    throw  Exception "Foo", tag => "ABC.1234";

I don't know about you, but I think this is cool.  Talk about
DWIM!  Good old Perl.

So now, in Try.pm, If you throw a string, you get an Exception
anyway:

    throw "A Message", ...;

is now the same as:

    throw Exception "A Message", ...;

You can't say C<throw $@> to re-raise an exception any more,
but you can say $@->throw or use a simple bare C<throw;>!
And C<throw;> with @@ == 0 raises a simple Exception!

I'll modify RFC 88 to change the throw syntax from:

    <throw> := throw <E> <message> <options> ;

    <E> := <class> | <object>
to:
    <throw> := throw <class> <message> <options> ;
             | throw <string> <options> ;
             | throw;

and make the appropriate changes to the semantics.  And of course,
C<try> should accept an additional hook parameter that specifies
the class into which to instantiate string throws.

Seems obvious in retrospect; we already had <class> and <string>,
why did <E> have to be <class> | <object>?  Ah well, serendipity
is like that, I suppose.

Yours, &c, Tony Olekshy

Reply via email to