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:
parent
3c168ef332
commit
8fb25b6a38
1 changed files with 12 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue