[Xapian-discuss] PHP exceptions (was Re: Why is a "DocNotFoundError" when deleting a document a Fatal error in php?)

Olly Betts olly at survex.com
Mon Jan 2 05:16:31 GMT 2006


Not a very recent thread - I'm currently trying to fix all the
outstanding issues with the bindings.

On Fri, Oct 28, 2005 at 12:35:28PM +0200, Arjen van der Meijden wrote:
> Well, I've tried a trivial "fix" and that seems to work (of course only 
> if all Xapian::RuntimeErrors are to be PHP Warnings).

I'm not totally at ease with the idea that such exceptions just become
warnings, but I don't like them being fatal errors you can't suppress
either.

I think in this particular case, there's not much justification for
throwing an exception in C++ at all.  You can ignore it everything
will be fine (unlike failing to open a file, then trying to read
from it), and a common way to handle failing to delete a document
will be to just ignore it.

But this isn't really the time to make radical changes to the C++
API's exception handling.

I'm also not keen on labouriously annotating every method to make up
for PHP4's lack of exceptions.  So I think this approach is probably
as good as it gets for PHP4.  But for PHP5, I've just written code to
actually throw exceptions (currently just as the standard Exception
class rather than as a DocNotFoundError).

> This'll yield warnings instead of errors in php. But it of course 
> doesn't stop processing anymore, so the Database_get_document will 
> return a Document-resource instead of something like false or null, that 
> may also need a fix but I haven't checked how to do that.

I think it should be easy to force a return of NULL after issuing the
warning.

Cheers,
    Olly



More information about the Xapian-discuss mailing list