httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Hedges <hed...@formdata.biz>
Subject Re: suggestion for APR::Error docs
Date Wed, 22 Dec 2010 18:15:45 GMT

On Wed, 22 Dec 2010, Torsten Förtsch wrote:

> On Tuesday, December 21, 2010 23:47:42 Mark Hedges wrote:
> > Seems to be some squirliness in this doc.  Is this more clear?  --mark--
> >
> To me the original version looks clearer. It says quite clearly "if I can
> handle the exception do so else propagate".
>
> However, the sigil before "ref" is certainly a typo. Also, I prefer "and"
> instead of "&&" in such cases. But that's just me.

The original version (ref typo corrected) is this:

    eval { $obj->mp_method() };
    if ($@ && ref $@ eq 'APR::Error' && $@ == $some_code) {
        # handle the exception
    }
    else {
        die $@; # rethrow it
    }

In the doc case, it would always die, even when there is no
exception.  If the first condition was not true, then 'else'
would die - always.

You could do this:

    eval { $obj->mp_method() };
    if ($@ && ref $@ eq 'APR::Error' && $@ == $some_code) {
        # handle the exception
    }
    elsif ($@) {
        die $@; # rethrow it
    }

But it seems logically cleaner to do something like what I suggested.
And, isn't it possible 'ref' is an APR::Request::Error or another
subclass of APR::Error?

    eval { $obj->mp_method() };
    if ($@) {
        my $ref = ref $@;
        if ($ref) {
            if ($@->isa('APR::Error') && $@ == $some_code) {
                # handle the exception
            }
            else {
                die $@; # rethrow APR::Error
            }
        }
        else {
            die $@; # unknown non-blessed error
        }
    }

--mark--
Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message