views:

47

answers:

2

Another co-worker and I have been heavily modifying the PHP Zookeeper extension but the one thing really bothering me is the reliance on PHP error's vs Exceptions.

The original source is here: http://github.com/andreiz/php-zookeeper/blob/master/php_zookeeper.c#L209

Instead it would be nicer to throw up a Zookeeper_NodeNotExists or similar except I have no idea what the API call in c is.

I've tried googling and got a cornucopia result set of Exceptions in the PHP language, the PHP manual doesn't seem to mention them, and I can't remember which PHP stock extensions throw exception for you. Is there an alternative source of documentation on the PHP/Zend c API out there?

A: 

Checking out lxr.php.net, I started with Sqlite.c which I knew threw an exception and found

via sqlite - http://lxr.php.net/opengrok/xref/PHP_5_3/ext/sqlite/sqlite.c#46

#include "zend_exceptions.h"

In zend_exceptions.h, it looks like a RuntimeException can be raised via a simple call to

zend_throw_exception(...)

In use examples include - http://lxr.php.net/opengrok/s?refs=zend_throw_exception&project=PHP_5_3

The Sqlite3 extension uses it like so:

zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Already initialised DB Object", 0 TSRMLS_CC);

where I infer that zend_exception_get_default() gets a reference/handle to RuntimeException, the 2nd argument is the Exception message, and all other work is delegated.

David