aboutsummaryrefslogtreecommitdiff
path: root/Lib/exception.i
diff options
context:
space:
mode:
authorDave Beazley <dave-swig@dabeaz.com>2002-11-30 22:01:28 +0000
committerDave Beazley <dave-swig@dabeaz.com>2002-11-30 22:01:28 +0000
commit12a43edc2df8853e8e0315f742e57be88f0c4269 (patch)
treee3237f5f8c0a67c9bfa9bb5d6d095a739a49e4b2 /Lib/exception.i
parent5fcae5eb66d377e1c3f81da7465c44a62295a72b (diff)
downloadswig-12a43edc2df8853e8e0315f742e57be88f0c4269.tar.gz
The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Lib/exception.i')
-rw-r--r--Lib/exception.i187
1 files changed, 108 insertions, 79 deletions
diff --git a/Lib/exception.i b/Lib/exception.i
index 1d6a9e35e..de90e2ef6 100644
--- a/Lib/exception.i
+++ b/Lib/exception.i
@@ -5,56 +5,6 @@
//
// This SWIG library file provides language independent exception handling
-#ifdef AUTODOC
-%section "Exception Handling Library",info,after,pre,nosort,skip=1,chop_left=3,chop_right=0,chop_top=0,chop_bottom=0
-
-%text %{
-%include exception.i
-
-This library provides language independent support for raising scripting
-language exceptions in SWIG generated wrapper code. Normally, this is
-used in conjunction with the %except directive.
-
-To raise an exception, use the following function call :
-
- SWIG_exception(int exctype, char *msg);
-
-'exctype' is an exception type code and may be one of the following :
-
- SWIG_MemoryError
- SWIG_IOError
- SWIG_RuntimeError
- SWIG_IndexError
- SWIG_TypeError
- SWIG_DivisionByZero
- SWIG_OverflowError
- SWIG_SyntaxError
- SWIG_ValueError
- SWIG_SystemError
- SWIG_UnknownError
-
-'msg' is an error string that should be reported to the user.
-
-The library is normally used in conjunction with the %except directive
-as follows :
-
-%except {
- try {
- $function
- } catch RangeError {
- SWIG_exception(SWIG_IndexError,"Array index out of bounds");
- } catch(...) {
- SWIG_exception(SWIG_UnknownError,"Uncaught exception");
- }
-}
-
-It is important to note that the SWIG_exception() function is only available
-to the C code generated by SWIG. It is not available in the scripting language
-interface itself.
-%}
-
-#endif
-
%{
#define SWIG_MemoryError 1
#define SWIG_IOError 2
@@ -71,7 +21,7 @@ interface itself.
#ifdef SWIGTCL8
%{
-#define SWIG_exception(a,b) { Tcl_SetResult(interp,b,TCL_VOLATILE); return TCL_ERROR; }
+#define SWIG_exception(a,b) { Tcl_SetResult(interp,b,TCL_VOLATILE); SWIG_fail; }
%}
#else
#ifdef SWIGTCL
@@ -83,19 +33,20 @@ interface itself.
#ifdef SWIGPERL5
%{
-#define SWIG_exception(a,b) croak(b)
+#define SWIG_exception(a,b) SWIG_croak(b)
%}
#endif
-#ifdef SWIGPERL4
+#ifdef SWIGPHP4
%{
-#define SWIG_exception(a,b) fatal(b)
+/* We should make use of "code" if we can */
+#define SWIG_exception(code, msg) { zend_error(E_ERROR, msg); }
%}
#endif
#ifdef SWIGPYTHON
%{
-static void _SWIG_exception(int code, char *msg) {
+static void _SWIG_exception(int code, const char *msg) {
switch(code) {
case SWIG_MemoryError:
PyErr_SetString(PyExc_MemoryError,msg);
@@ -133,7 +84,7 @@ static void _SWIG_exception(int code, char *msg) {
}
}
-#define SWIG_exception(a,b) { _SWIG_exception(a,b); return NULL; }
+#define SWIG_exception(a,b) { _SWIG_exception(a,b); SWIG_fail; }
%}
#endif
@@ -171,54 +122,132 @@ static void _SWIG_exception(int code, char *msg) {
%}
#endif
-#ifdef SWIGJAVA
+#ifdef SWIGMZSCHEME
+
%{
-static void _SWIG_exception(JNIEnv *jenv, int code, const char *msg) {
- char exception_path[512];
- const char *classname;
- const char *class_package = "java/lang";
-
+ static void _SWIG_exception (int code, const char *msg) {
+#define ERROR(errname) \
+ scheme_signal_error(errname " (%s)", msg);
+#define MAP(swigerr, errname) \
+ case swigerr: \
+ ERROR(errname); \
+ break
+ switch (code) {
+ MAP(SWIG_MemoryError, "swig-memory-error");
+ MAP(SWIG_IOError, "swig-io-error");
+ MAP(SWIG_RuntimeError, "swig-runtime-error");
+ MAP(SWIG_IndexError, "swig-index-error");
+ MAP(SWIG_TypeError, "swig-type-error");
+ MAP(SWIG_DivisionByZero, "swig-division-by-zero");
+ MAP(SWIG_OverflowError, "swig-overflow-error");
+ MAP(SWIG_SyntaxError, "swig-syntax-error");
+ MAP(SWIG_ValueError, "swig-value-error");
+ MAP(SWIG_SystemError, "swig-system-error");
+ default:
+ ERROR("swig-error");
+ }
+#undef ERROR
+#undef MAP
+ }
+
+#define SWIG_exception(a,b) _SWIG_exception(a, b)
+%}
+#endif
+#ifdef SWIGJAVA
+%{
+static void SWIG_JavaException(JNIEnv *jenv, int code, const char *msg) {
+ SWIG_JavaExceptionCodes exception_code = SWIG_JavaUnknownError;
switch(code) {
case SWIG_MemoryError:
- classname = "OutOfMemoryError";
+ exception_code = SWIG_JavaOutOfMemoryError;
break;
case SWIG_IOError:
- classname = "IOException";
- class_package = "java/io";
+ exception_code = SWIG_JavaIOException;
break;
case SWIG_SystemError:
case SWIG_RuntimeError:
- classname = "RuntimeException";
+ exception_code = SWIG_JavaRuntimeException;
break;
case SWIG_OverflowError:
case SWIG_IndexError:
- classname = "IndexOutOfBoundsException";
+ exception_code = SWIG_JavaIndexOutOfBoundsException;
break;
case SWIG_DivisionByZero:
- classname = "ArithmeticException";
+ exception_code = SWIG_JavaArithmeticException;
break;
case SWIG_SyntaxError:
case SWIG_ValueError:
case SWIG_TypeError:
- classname = "IllegalArgumentException";
+ exception_code = SWIG_JavaIllegalArgumentException;
break;
case SWIG_UnknownError:
default:
- classname = "UnknownError";
+ exception_code = SWIG_JavaUnknownError;
break;
}
- sprintf(exception_path, "%s/%s", class_package, classname);
- jclass excep;
- jenv->ExceptionClear();
- excep = jenv->FindClass(exception_path);
- if (excep)
- {
- jenv->ThrowNew(excep, msg);
- }
+ SWIG_JavaThrowException(jenv, exception_code, msg);
}
-#define SWIG_exception(a,b) { _SWIG_exception(jenv, a,b); }
+#define SWIG_exception(code, msg) { SWIG_JavaException(jenv, code, msg); }
%}
#endif // SWIGJAVA
+#ifdef SWIGOCAML
+%{
+#define OCAML_MSG_BUF_LEN 1024
+static 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
+
+#ifdef SWIGRUBY
+%{
+static void _SWIG_exception(int code, const char *msg) {
+ switch (code) {
+ case SWIG_MemoryError:
+ rb_raise(rb_eNoMemError, msg);
+ break;
+ case SWIG_IOError:
+ rb_raise(rb_eIOError, msg);
+ break;
+ case SWIG_RuntimeError:
+ rb_raise(rb_eRuntimeError, msg);
+ break;
+ case SWIG_IndexError:
+ rb_raise(rb_eIndexError, msg);
+ break;
+ case SWIG_TypeError:
+ rb_raise(rb_eTypeError, msg);
+ break;
+ case SWIG_DivisionByZero:
+ rb_raise(rb_eZeroDivError, msg);
+ break;
+ case SWIG_OverflowError:
+ rb_raise(rb_eRangeError, msg);
+ break;
+ case SWIG_SyntaxError:
+ rb_raise(rb_eSyntaxError, msg);
+ break;
+ case SWIG_ValueError:
+ rb_raise(rb_eArgError, msg);
+ break;
+ case SWIG_SystemError:
+ rb_raise(rb_eFatal, msg);
+ break;
+ case SWIG_UnknownError:
+ rb_raise(rb_eRuntimeError, msg);
+ break;
+ default:
+ break;
+ }
+}
+
+#define SWIG_exception(a, b) _SWIG_exception((a), (b))
+%}
+#endif
+
/* exception.i ends here */