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

Re: Try/Catch Exception Objects: Possible?

Thread Previous | Thread Next
From:
David Nicol
Date:
July 25, 2013 13:16
Subject:
Re: Try/Catch Exception Objects: Possible?
Message ID:
CAFwScO-5EabPcSh8_0vzMhGqWTi1MP_M3M-pJx_uwS9ag0G5sw@mail.gmail.com
On Thu, Jul 25, 2013 at 6:13 AM, David E. Wheeler <david@justatheory.com> wrote:


>> I don't know if a stack is really needed, a localizable $THROWN_PANIC
>> might be enough.
>
> I don’t understand. What is $THROWN_PANIC? If it is an exception object, why would it not need a trace?
>
> I nearly always want a trace for my exception objects. The idea, for me, is such exceptions should be unexpected and reported to the developer, who will likely need the stack.

by "stack" here I meant more than one active exception at the same
time, possibly living in @@. I did not intend to allude to traces.

$THROWN_PANIC is a placeholder for the new single thing that is not $@.






> Yeah, though if we went with the nested catch, it would affect the lexical scope in which it is declared, block or function. Perhaps not file, though.

why not file?



>> My internal jury is still out on the question of, does it make more
>> sense to deal with the last exception thrown, the first exception
>> thrown, or to have a queue of them that must all be handled to resume
>> normal operations. I don't think it's possible to have simultaneous
>> exceptions in C++, outside of an easy-to-imagine system that might
>> embed a list of complaints in a complicated exception object.
>
> Could be a chain, though. For example, Throwable has a previous_exception accessor, which tends to be pretty handy.

or a "consume exception" operator that keeps producing them until it
runs out and must be called in a loop. There would also have to be a
way to inspect the current one. So just declaring some conventions
around use of @@ gives everything we could possible need.

Please tell more about Throwable's previous_exception accessor. I'm
guessing it stashes the active exception when throwing while handling.
Is there sugar for getting the first-thrown?

>
> Does Perl have a DEFER block? If not, should it be a part of this conversation?

Perl does not have a formal DEFER block. CPAN has Scope::OnExit and a
pure-perl version providing similar semantics but clunky syntax, using
the reassignment of previous values to localized variables as the
trigger for running a coderef. DEFER is an essential part of golang's
exception handling, and therefore belongs in this conversation.

gotta run late for work

dln

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