I have extended the RFC 88 Perl 5 reference implementation to
support rudimentary POST and CATCH blocks, for which I've used
"always" and "except" as the keywords.

The new version is http://www.avrasoft.com/perl6/try6-2021.txt
Save that file as Try.pm and perl -we "use Try regress => 1"
to run the regression tests.

All I've done so far is export "always" and "except" subroutines
that splice equivalent "finally" and "catch" arguments into try's
argument list.  This means that, for now, always and except only
work in try blocks, and their error messages are reported as those
of the generated finally and catch blocks.

However, as a result, the following regression tests do work:

    !always-1       Always stacks a finally.

        try sub {
            print "1\n";
            always sub { print "3\n"; };
            print "2\n";
            };

      =expect

        1
        2
        3

    !except-1       Except stacks a catch.

        try sub {
            print "1\n";
            except sub { print "2\n"; };
            die;
            print "BAD\n";
            };

      =expect

        1
        2

And, it does mean that we have a defined semantics for the purpose
of discussion, upon which perhaps we can derive the detailed
semantics for Perl 6's exception handling mechanism.

Please bear with me.  The purpose of this exercise is to make
Perl 6 better, not to make it into my version of Java.  In fact,
I've never programmed in Java.  Thank you very much.  I learned to
appreciate the beauty and elegance of structured exception handling
in Scheme and Object Pascal (one of which is a B&D language, one of
which is not).

I'm just trying to figure out how I might be able to make my
miniscule contribution to Perl 6 by writing the exception handling
FAQ.  When I'm explaining

        { f() always { g() except Error::IO { h() } } }

I need to know: does h() get called if f() raised an Error::IO or
only if g() does?

Yours, &c, Tony Olekshy

Reply via email to