From 8fb25b6a38e41d8147d5f0767d64ab269f0fdc66 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 25 May 2021 16:33:01 +1200 Subject: 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.) --- Lib/exception.i | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/exception.i b/Lib/exception.i index 9bf3a19d4..020ee1150 100644 --- a/Lib/exception.i +++ b/Lib/exception.i @@ -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 -- cgit v1.2.1