[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: A common base exception object for Perl - RFC
"Redford, John" wrote:
> 1. Make the base class minimal. Do not include any special fields like
> 'name', 'errcode', or 'exitcode'. Don't include any fields or methods,
> just the '""' override.
Maybe. I'd like to see at least the standard Perl behaviour in the base
class - ie. error text, exit code and caller info. Name: OK, class could
come from the exception class as per C<Error>.
> 2. 'toString' instead of 'render'.
ACK.
> 3. Base implementation of '""' as follows:
> sub { $_[0]->can('toString') ? $_[0]->toString() : "" };
> Just enough to avoid errors with existing code, without requiring a
> conversion function to exist.
If the base class contains at least an error text attribute, it can have
a real stringification method, otherwise OK.
> 4. This needs to work:
> my $e = new Exception;
> die $e;
> It should not be necessary to write:
> $e->raise;
That was implicit in my initial message (if not actually stated :)
> 5. Will Carp routines behave properly? I know that 'die' will happily pass
> along a reference in $@, but won't Carp always stringify it? What would be
> the point of using a reference type which was always converted into a
> string before it could be caught?
Not much I can do about this other than patching C<Carp>. However,
equivalent functionality to C<Carp> would be available either in my base
class or in, say, C<Exception::Carp>.
> Regardless, I think it would be more
> natural to write:
> confess $e;
Matter of style and preference. I can always put selected methods into
C<@EXPORT_OK> if the consensus is that this is a Good Thing. For myself,
I prefer object syntax.
> Right now everyone assumes that every $@ is a string. It would be little
> improvement (for me, at least) to assume that everything in $@ is either a
> string or a HASH ref which has a field 'errcode'.
>
> I would want to see a model which encouraged/forced subclassing of
> Exception in order to get a useful exception object, resulting in code
> like:
>
> if ( ref $@ and $@->isa{'MyException') ) { ... }
>
> instead of code like:
>
> if ( ref $@ and $@->{class} eq 'MyException' ) { ... }
Agreed.
> The Exception object model should not preclude the use of "better" Perl
> objects which are not based on HASH refs (or pseudohashes). If common
> practice is to treat $@ as "A string or a HASH ref", it becomes impossible
> (again!) to use arbitrary reference types in $@.
Agreed again - nothing in my interface precludes non-HASH
implementations, nobody should ever access properties of an exception
object other than via methods.
Pete
--
use Disclaimer::Standard; # Motorola GSM Software Factory
my $phone='+44 1793 564450'; # "'Not twisted,' Salzy once said of
my $fax='+44 1793 566918'; # her own passion, 'it is helical.
my $mobile='+44 7973 725120'; # That sounds better.'"
- References to:
-
"Redford, John" <John.Redford@fmr.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]