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

Re: Try/Catch Exception Objects: Possible?

Thread Previous
From:
Tom Christiansen
Date:
July 24, 2013 00:42
Subject:
Re: Try/Catch Exception Objects: Possible?
Message ID:
5444.1374626500@chthon
>--f46d043bdf6a18fbcb04e220e781
>Content-Type: text/plain; charset=UTF-8

>On Mon, Jul 22, 2013 at 4:44 PM, David E. Wheeler <david@justatheory.com<SNIP>

>>
>> Crazy? Impossible? Terrifying?
>>

> Have you looked at the way Golang does exceptions? Their documentation
> discourages
> exception-driven control flow -- everything returns lists, and the
> convention is to make the second element the completion status, to avoid
> the out-of-band problem of returning special failure values -- but one
> could do it with their available tools.

> The most important of these tools is a deferred block, which executes at
> scope-tear-down time, like CPAN's OnScopeExit or LocalOnExit. They also
> have a global exception objectl like Perl's $@, which is loaded with
> "panic" and can be consumed with "recover." If Perl were to (1) support a
> DEFER block that worked that way and (2) stop clobbering defined $@ (has
> that been fixed? I remember discussion about automatically localizing $@ in
> DESTROY) until it is consumed by an equivalent to golang's "recover" that
> would be, in my opinion, more powerful than adopting the try/catch  idiom
> into the core language.

> Maybe golang-style panics would be best given their own parallel system,
> rather than touching the semantics of $@, no matter how slightly.

> In short, I'm opposed to try/catch, as I think it's a tired idiom with
> superior alternatives, including what Perl's already got.

I would like to see this angle investigated more before we all go tripping
merrily down the dodgily paved road that Java and C++ took.

--tom

Thread Previous


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