develooper Front page | perl.perl5.porters | Postings from July 2013

Re: Try/Catch Exception Objects: Possible?

Thread Previous | Thread Next
From:
David Golden
Date:
July 23, 2013 19:05
Subject:
Re: Try/Catch Exception Objects: Possible?
Message ID:
CAOeq1c9Qppij+t-BsSZg-+bnyXOnBH57XUWMW1bZrsahCX6QJA@mail.gmail.com
On Tue, Jul 23, 2013 at 2:32 PM, David Golden <xdg@xdg.me> wrote:
> I would recommend using $@ for familiarity.

Expanding on this thought:

I see no problem omitting $@ entirely in the context of a
well-designed try/catch syntax that doesn't need to park the exception
in a temporary variable (e.g. if 'catch FOO' catches any exception
that isa 'FOO').  However, if the exception needs to be parked in a
global, I'd park it in $@ for consistency with what happens outside
try/catch.

I'd also probably be happy with something that moved us away from
keeping errors in globals entirely during exception handling and just
passed them as arguments to handler blocks.  E.g.:

    try {
        risky()
    }
    catch error::io, error::network {
        my $err = shift;
        # do something useful
        ...;
    }
    otherwise {
        log_this( shift );
    }
    finally {
        clean_up();
    }

David

-- 
David Golden <xdg@xdg.me>
Take back your inbox! → http://www.bunchmail.com/
Twitter/IRC: @xdg

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About