在我的C扩展中,我可以使用zend_throw_exception向调用函数抛出一个
PHP异常.该函数的第一个参数是zend_class_entry,它指定要抛出的异常类型.我从zend_exceptions.h中的文档中知道,我可以使用zend_exception_get_default()来使用默认的异常类型.
但是,它也说我可以传递派生类.在哪里可以找到派生的内置异常的类条目,例如InvalidArgumentException?
所有例外都在源代码中定义;
原文链接:https://www.f2er.com/php/136611.htmlPHP-5.5.15/ext/spl/spl_exceptions.h
并且可以在安装devel包时找到(例如yum install PHP-devel on fedora);
/usr/include/PHP/ext/spl/spl_exceptions.h
并包含以下内容;
extern PHPAPI zend_class_entry *spl_ce_LogicException; extern PHPAPI zend_class_entry *spl_ce_BadFunctionCallException; extern PHPAPI zend_class_entry *spl_ce_BadMethodCallException; extern PHPAPI zend_class_entry *spl_ce_DomainException; extern PHPAPI zend_class_entry *spl_ce_InvalidArgumentException; extern PHPAPI zend_class_entry *spl_ce_LengthException; extern PHPAPI zend_class_entry *spl_ce_OutOfRangeException; extern PHPAPI zend_class_entry *spl_ce_RuntimeException; extern PHPAPI zend_class_entry *spl_ce_OutOfBoundsException; extern PHPAPI zend_class_entry *spl_ce_OverflowException; extern PHPAPI zend_class_entry *spl_ce_RangeException; extern PHPAPI zend_class_entry *spl_ce_UnderflowException; extern PHPAPI zend_class_entry *spl_ce_UnexpectedValueException;
并且可以按照单元测试抛出;
zend_throw_exception_ex(spl_ce_InvalidArgumentException,0 TSRMLS_CC,"array size cannot be less than zero");