Re: suggestion for APR::Error docs

Mark Hedges <[email protected]> Wed, 22 Dec 2010 10:15:45 -0800 (PST)
Newsgroups gmane.comp.apache.apreq
Message-ID <[email protected]>
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--8323328-1054204521-1293041745=:24857
Content-Type: TEXT/PLAIN; charset=iso-8859-1
Content-Transfer-Encoding: QUOTED-PRINTABLE


On Wed, 22 Dec 2010, Torsten F=F6rtsch 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' && $@ =3D=3D $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' && $@ =3D=3D $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 =3D ref $@;
        if ($ref) {
            if ($@->isa('APR::Error') && $@ =3D=3D $some_code) {
                # handle the exception
            }
            else {
                die $@; # rethrow APR::Error
            }
        }
        else {
            die $@; # unknown non-blessed error
        }
    }

--mark--
--8323328-1054204521-1293041745=:24857--