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

Re: Try/Catch Exception Objects: Possible?

Thread Previous | Thread Next
David Golden
July 23, 2013 22:08
Re: Try/Catch Exception Objects: Possible?
Message ID:
On Tue, Jul 23, 2013 at 3:56 PM, David E. Wheeler <> wrote:
> The catch block should not do conditional execution. One should use a switch statement or whatever inside the catch block.

Why not? Please make a real case for that opinion.  If the common case
is going to be tests for certain types of exceptions or a given/when
block, why wouldn't we want to provide sugar for that?  (Which is why
my playful example had "catch CONDITION" and "otherwise BLOCK".)

> Might be nice to pass the error, but no other block works that way (only anonymous subs), so using a lexical $_ would probably be the way to go (again, like Try::Tiny).

Do you mean "localized $_" instead of "lexical $_"?  Didn't we just
decide that lexical $_ is a problem?  Even so, why should we continue
to perpetuate the use of globals which can be modified by code called
by an error handler?

How about using a non-argument lexical like "for" blocks:

   for my $foo ( list() ) { ... }

For try/catch:

   try { ... }
   catch my $err { ... }

And like "for", omit "my $err" to have the exception in "$_".

If we went for omitting conditional logic from catch clauses, then
that sort of shortcut seems useful.

    try {
    catch my $err {


David Golden <>
Take back your inbox! →
Twitter/IRC: @xdg

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