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

Re: Try/Catch Exception Objects: Possible?

Thread Previous | Thread Next
From:
Kent Fredric
Date:
July 22, 2013 22:26
Subject:
Re: Try/Catch Exception Objects: Possible?
Message ID:
CAATnKFBmRXm5eXcKTaDd+t=J3_fbo5vG-xs04eO1o9WGAEEqvg@mail.gmail.com
On 23 July 2013 09:44, David E. Wheeler <david@justatheory.com> wrote:
> Porters,
>
> * Having `die` create exception objects
> * Those objects would stringify to the current string format
> * Having core language exceptions be objects

This criteria list is what gives me the impression exceptions need
their own reftype, and in that form,  die is a special construct (
like bless, and qr/ / ) that creates and throws an exception
reference.

Exceptions and Regexps are very similar in that they both obviously
stringify, and both are expected by older code to be strings.

The reason I don't want them to be "real objects" in the usual sense,
is that implementing a real-object based exception class is messy, and
its easy to miss out important things, like backtrace support (
working on tired memory here, but my experience with exception objects
so far is without explicity codifying backtrace support of some kind,
backtraces are severely limited, more so than what you get with simple
strings )

And the present state of object-based exceptions on CPAN seems to be
self-evidently limiting adoption, because every time I  try to reach
for full exception objects, I'm forced to reach for a lot more than
just "die <reason>".

> * the new syntax would be no big deal, thanks to `feature`.

Additonally, if it was a special reftype, contexts without the feature
could be told to assume string semantics during compile, and exception
refs would invisibly degrade to strings.

> * Changing `die` to create exception objects would be straight-forward
> * Changing core errors to category-specific exceptions would mostly be
>   busy work, though maybe it can be derived from autodie


Even if my exact ideas are awful, or yours are, this is a much needed
discussion imo. Though, I just fear if we try arguing they should be
objects in the same sense as most present objects ( ie: with a
matching package and a load of boring messy pure-perl plumbing ),
we'll get side tracked about bikeshedding about how it would be really
nice to have something Moo/Moose like in core.

Besides, I get the impression the guts of doing anything serious with
Exceptions may even be easier to approach from the Perl & C side of
the equation than it is to do it entirely in pureperl.


-- 
Kent

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