summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2021-05-25 16:33:01 +1200
committerOlly Betts <olly@survex.com>2021-05-25 16:33:01 +1200
commit8fb25b6a38e41d8147d5f0767d64ab269f0fdc66 (patch)
tree4a41304d86d6f28086c1805fa33535e9f6658733 /Lib
parent3c168ef332ed66929c404cbf8c02ec04bfd02780 (diff)
downloadswig-8fb25b6a38e41d8147d5f0767d64ab269f0fdc66.tar.gz
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.)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/exception.i13
1 files changed, 12 insertions, 1 deletions
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