[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Exception handling in Perl or rather: non-local goto's
- Subject: Re: Exception handling in Perl or rather: non-local goto's
- From: Erik Huelsmann <..hidden..>
- Date: Wed, 22 Jun 2011 21:42:54 +0200
Hi Chris,
On Tue, Jun 21, 2011 at 12:21 AM, Chris Travers <..hidden..> wrote:
> On Mon, Jun 20, 2011 at 2:49 PM, Erik Huelsmann <..hidden..> wrote:
>> Last weekend, I added non-local gotos using exception handling to
>> replace 'exit;' calls.
>>
>> Today, mst showed up on IRC (coincidentally), telling me about an
>> issue with running our code under suEXEC conditions. That bit was
>> fixed in r3304, but as he did some code review, he pointed out my use
>> of Error.pm is really 'so 2005' -- Error.pm having been superseeded by
>> Try::Tiny.
>
> I suppose there are worse things than using programming practices that
> are "so 2005." It would be more helpful if we could have some idea
> what the relevant cost/benefits of an approach are rather than just a
> blanket characterization. Is the module unmaintained? What precisely
> are the issues? If we don't know what the issues are and the code
> works, let's not spend a lot of effort rewriting.s
Well, I've spent some time researching the issues which are supposedly
involved, but I'm not getting much further than the following - rather
generic - statement from the Error.pm perlpod pages:
"""Using the "Error" module is no longer recommended due to the
black-magical nature of its syntactic sugar, which often tends to
break. Its maintainers have stopped actively writing code that uses
it, and discourage people from doing so. See the "SEE ALSO" section
below for better recommendations."""
>From the above, I would say that it's indeed no longer maintained. But
nothing in the page nor in my web searches indicates what would "often
break".
>> When reading the POD for Try::Tiny, I get extremely unhappy about its
>> treatment of the $@ variable. However, possibly, that doesn't matter
>> much for our specific purpose.
>
> Can you be specific here?
Yes: studying the pages for Try::Tiny again, their discussion of the
$@ variable is really about Perl's general "behaviour", meaning I was
misunderstanding the discussion to be specifically about Try::Tiny and
my disgust is more with Perl in general than with Try::Tiny.
Basically, instead of declaring a variable to store the exception
object into (like e.g. Java in its "catch (<class> <var>) {}"), any
code can store a value in $@. That means you really can't depend on
the value of $@ to stay "unclobbered".
Concluding: Error.pm may be considered unmaintained; switching to
Try::Tiny seems a good option, with the drawbacks being general Perl
gotcha's.
It'll take a bit of getting used to, but I guess I'll manage :-)
Bye,
Erik.