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:
Jan Dubois
Date:
June 25, 2008 00:00
Subject:
RE: Why $@ makes me cry (was Re: Generic system() replacements)
Message ID:
001701c8d645$e40cf100$ac26d300$@com
On Tue, 24 Jun 2008, Abigail wrote:
> 
> On Sat, Jun 21, 2008 at 12:25:53PM +1000, Paul Fenwick wrote:
> >
> > 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.
>
> 
> Eh, I know I shouldn't have done this, but I have written code that could
> die inside a DESTROY, with an eval to capture this exception. That code
> would fail if $@ is saved before a DESTROY and then restored.

Can you post some code example that does this? A call to die($msg)
inside DESTROY does not raise an exception, it simply does the
equivalent of

    $@ .= "\t(in cleanup) $msg";

with some additional checking to avoid appending the same message
multiple times.  It also prints this appended part as a "misc" warning.
Well, at least the code looks like you are supposed to suppress the
warning, but it doesn't seem to work. But anyway, it does *not* raise
an exception as far as I can tell:

#!perl
use strict;
use warnings;

$|++;

sub foo::DESTROY {
    print "inside foo::DESTROY\n";
    die "trying to die in foo::DESTROY\n";
}

no warnings "misc";
$@ = "whatever\n";
do { bless [] => "foo" };
print "\$\@ is $@\n";
__END__

> Now, I don't really care about this specific piece of code (I doubt it's
> still running), but there might be some other code out there that relies
> on this. That's not to say I would oppose such a change, IMO, the benefits
> outweight the breakage of code written by a handful of freaks, but in general
> we do care about backwards compat issues.

I have written a (possible naïve) patch for this already, but wasn't quite
sure what to do with the "\t(in cleanup)" additions.  I guess people expect
those to go into @@ instead of being appended to $@ anymore, right?

That is not a backwards compatible change.  However, we could re-attach the
@@ error messages to $@ after restoring the saved copy, if we really wanted to.

Cheers,
-Jan



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