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

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

Thread Previous | Thread Next
From:
Paul Fenwick
Date:
June 20, 2008 17:04
Subject:
Why $@ makes me cry (was Re: Generic system() replacements)
Message ID:
485C4584.60007@perltraining.com.au
G'day Aristotle / p5p,

Aristotle Pagaltzis wrote:

> There are various cases in which $@ can be swallowed before you
> get to the `if` condition. There was some constellation with
> exceptions in `DESTROY` in objects going out of scope at the end
> of the `eval` block and other cases as “interesting” as that one.

Gah, I didn't even think of DESTROY; the following simply prints "Bye from Foo":

	sub Foo::DESTROY { print "Bye from Foo\n"; eval {}; }

	eval {
		my $x = bless({},"Foo");
		die "Oh noes!";
	};

	print $@ if $@;

> The only 100% reliable indicator for whether an `eval` block executed 
> is whether it returned undef.

And even then, gaining access to $@ may not be possible.

> I have said before that I should trawl my mailing list archives
> someday for all the cases people have discovered and then attempt
> to write Unbreak::Eval.

Sounds like a lovely idea. ;)

Cheerio,

	Paul

-- 
Paul Fenwick <pjf@perltraining.com.au> | http://perltraining.com.au/
Director of Training                   | Ph:  +61 3 9354 6001
Perl Training Australia                | Fax: +61 3 9354 2681

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