[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: __DIE__ and exception hooks
On Wed, 19 Jan 2000 11:09:03 GMT, Pete Jordan wrote:
>So what it comes down to is:
>
>1. Perl provides an (experimental) facility to pass references into
>C<die> that will, with a horrible inevitability, find their way into
>C<$@> when C<eval> is in use.
>
>2. If anyone makes use of this facility in a module (outside of the sort
>of closed system in which I'm currently operating), they will break not
>only conventional usage of C<$@> but also Perl's own default C<die>
>processing. Though the latter of course can be overridden. Probably
>simultaneously in a variety of mutually incompatible ways by different
>module authors.
>
>There are three possible solutions:
I think you missed the easiest one (been mentioned here before).
>A. Abandon structured exceptions in Perl. Not an acceptable option.
>
>B. Force the lusers to rewrite all their evals. Muharharharhar... etc.
>
>C. Define a Standard Perl Minimal Exception Object and integrate it such
>that, at the very least, scalar fetch access to C<$@> returns an error
>text string regardless of whether text or object were passed to C<die>.
D. Make the exception object overload stringify.
% perl -w -Ilib
package Foo;
use overload '""' => sub { shift->[0] };
sub new { my($c, $msg) = @_; bless [$msg], $c }
package main;
eval {
die Foo->new("gone fishin");
};
print $@;
__END__
gone fishin
Yes, we do need a module that can be subclassed from for throwing
such exception objects (similar to Tie::Array et al). The only
question now is, are you willing to write it?
Sarathy
gsar@ActiveState.com
- Follow-Ups from:
-
Pete Jordan <pjordan1@email.mot.com>
- References to:
-
Pete Jordan <pjordan1@email.mot.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]