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

Re: Try/Catch Exception Objects: Possible?

Thread Previous | Thread Next
David Nicol
July 22, 2013 22:07
Re: Try/Catch Exception Objects: Possible?
Message ID:
On Mon, Jul 22, 2013 at 4:44 PM, David E. Wheeler <>wrote:

> Crazy? Impossible? Terrifying?

Have you looked at the way Golang does exceptions? Their documentation
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.

You've got to wiggle before you can crawl

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About