diff options
Diffstat (limited to 'Lib/exception.i')
-rw-r--r-- | Lib/exception.i | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/Lib/exception.i b/Lib/exception.i index da0d56cdd..ee9ce9bc6 100644 --- a/Lib/exception.i +++ b/Lib/exception.i @@ -12,13 +12,6 @@ %insert("runtime") "swigerrors.swg" -#ifdef SWIGPHP5 -%{ -#include "zend_exceptions.h" -#define SWIG_exception(code, msg) do { zend_throw_exception(NULL, (char*)msg, code TSRMLS_CC); goto thrown; } while (0) -%} -#endif - #ifdef SWIGPHP7 %{ #include "zend_exceptions.h" @@ -134,33 +127,48 @@ SWIGINTERN void SWIG_JavaException(JNIEnv *jenv, int code, const char *msg) { #ifdef SWIGOCAML %{ -#define OCAML_MSG_BUF_LEN 1024 -SWIGINTERN void SWIG_exception_(int code, const char *msg) { - char msg_buf[OCAML_MSG_BUF_LEN]; - sprintf( msg_buf, "Exception(%d): %s\n", code, msg ); - failwith( msg_buf ); -} -#define SWIG_exception(a,b) SWIG_exception_((a),(b)) -%} -#endif - +SWIGINTERN void SWIG_OCamlException(int code, const char *msg) { + CAMLparam0(); -#ifdef SWIGCHICKEN -%{ -SWIGINTERN void SWIG_exception_(int code, const char *msg) { - C_word *a; - C_word scmmsg; - C_word list; - - a = C_alloc (C_SIZEOF_STRING (strlen (msg)) + C_SIZEOF_LIST(2)); - scmmsg = C_string2 (&a, (char *) msg); - list = C_list(&a, 2, C_fix(code), scmmsg); - SWIG_ThrowException(list); + SWIG_OCamlExceptionCodes exception_code = SWIG_OCamlUnknownError; + switch (code) { + case SWIG_DivisionByZero: + exception_code = SWIG_OCamlArithmeticException; + break; + case SWIG_IndexError: + exception_code = SWIG_OCamlIndexOutOfBoundsException; + break; + case SWIG_IOError: + case SWIG_SystemError: + exception_code = SWIG_OCamlSystemException; + break; + case SWIG_MemoryError: + exception_code = SWIG_OCamlOutOfMemoryError; + break; + case SWIG_OverflowError: + exception_code = SWIG_OCamlOverflowException; + break; + case SWIG_RuntimeError: + exception_code = SWIG_OCamlRuntimeException; + break; + case SWIG_SyntaxError: + case SWIG_TypeError: + case SWIG_ValueError: + exception_code = SWIG_OCamlIllegalArgumentException; + break; + case SWIG_UnknownError: + default: + exception_code = SWIG_OCamlUnknownError; + break; + } + SWIG_OCamlThrowException(exception_code, msg); + CAMLreturn0; } -#define SWIG_exception(a,b) SWIG_exception_((a),(b)) +#define SWIG_exception(code, msg) SWIG_OCamlException(code, msg) %} #endif + #ifdef SWIGCSHARP %{ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) { |