develooper Front page | perl.perl5.porters | Postings from June 2008

Re: Why $@ makes me cry (was Re: Generic system() replacements)

Thread Previous | Thread Next
From:
Bram
Date:
June 21, 2008 02:09
Subject:
Re: Why $@ makes me cry (was Re: Generic system() replacements)
Message ID:
20080621110810.m1tvai5h4w0gkcss@horde.wizbit.be
Citeren Paul Fenwick <pjf@perltraining.com.au>:

> However I believe there may be some merit in saving $@ before a DESTROY
> is called, and restoring it afterwards.  That allows destruction to
> occur as it always has, but prevents said destruction from clobbering
> $@.  I imagine trying to capture a $@ from object destruction that's
> essentially happening "between the lines" is going to be a rather rare
> occurrence indeed.
>

(Which can't be done automatically because that might break existing code...)

And note that a DESTROY block can alter more then just $@...

Perhaps the documentation of DESTROY should include the line:
   local($., $@, $!, $^E, $?);


What I've been thinking about with regards to eval would be to allow  
something like:

eval EXPR
eval BLOCK
eval EXPR, SCALAR
eval BLOCK, SCALAR


Where the last two could be used like:
   eval { die "foo" }, $my_err_variable;

which would place "foo" in $my_err_variable and leave $@ alone.


Kind regards,

Bram



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