php: SWIG_exception now maps code to exception class

This now determines the class of the exception object where a
suitable pre-defined PHP exception class exists - for example,
SWIG_TypeError -> PHP exception class TypeError.

Exception codes which don't naturally map to a pre-defined PHP
exception class are thrown as PHP class Exception (like all
PHP exceptions raised by SWIG_exception were before this change.)
This commit is contained in:
Olly Betts 2021-05-25 16:33:01 +12:00
commit 8fb25b6a38

View file

@ -14,7 +14,18 @@
#ifdef SWIGPHP
%{
#define SWIG_exception(code, msg) do { zend_throw_exception(NULL, (char*)msg, code); goto thrown; } while (0)
#if PHP_MAJOR >= 8
# define SWIG_HANDLE_VALUE_ERROR_FOR_PHP8 code == SWIG_ValueError ? zend_ce_value_error :
#else
# define SWIG_HANDLE_VALUE_ERROR_FOR_PHP8
#endif
#define SWIG_exception(code, msg) do { zend_throw_exception( \
code == SWIG_TypeError ? zend_ce_type_error : \
SWIG_HANDLE_VALUE_ERROR_FOR_PHP8 \
code == SWIG_DivisionByZero ? zend_ce_division_by_zero_error : \
code == SWIG_SyntaxError ? zend_ce_parse_error : \
code == SWIG_OverflowError ? zend_ce_arithmetic_error : \
NULL, msg, code); goto thrown; } while (0)
%}
#endif