added java exception support submitted by Tal Shalif <tal@slt.atr.co.jp>
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@614 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c86069d4f6
commit
33247d0e3c
1 changed files with 50 additions and 0 deletions
|
|
@ -171,4 +171,54 @@ static void _SWIG_exception(int code, char *msg) {
|
|||
%}
|
||||
#endif
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
%{
|
||||
static void _SWIG_exception(JNIEnv *jenv, int code, const char *msg) {
|
||||
char exception_path[512];
|
||||
const char *classname;
|
||||
const char *class_package = "java/lang";
|
||||
|
||||
|
||||
switch(code) {
|
||||
case SWIG_MemoryError:
|
||||
classname = "OutOfMemoryError";
|
||||
break;
|
||||
case SWIG_IOError:
|
||||
classname = "IOException";
|
||||
class_package = "java/io";
|
||||
break;
|
||||
case SWIG_SystemError:
|
||||
case SWIG_RuntimeError:
|
||||
classname = "RuntimeException";
|
||||
break;
|
||||
case SWIG_OverflowError:
|
||||
case SWIG_IndexError:
|
||||
classname = "IndexOutOfBoundsException";
|
||||
break;
|
||||
case SWIG_DivisionByZero:
|
||||
classname = "ArithmeticException";
|
||||
break;
|
||||
case SWIG_SyntaxError:
|
||||
case SWIG_ValueError:
|
||||
case SWIG_TypeError:
|
||||
classname = "IllegalArgumentException";
|
||||
break;
|
||||
case SWIG_UnknownError:
|
||||
default:
|
||||
classname = "UnknownError";
|
||||
break;
|
||||
}
|
||||
sprintf(exception_path, "%s/%s", class_package, classname);
|
||||
jclass excep;
|
||||
jenv->ExceptionClear();
|
||||
excep = jenv->FindClass(exception_path);
|
||||
if (excep)
|
||||
{
|
||||
jenv->ThrowNew(excep, msg);
|
||||
}
|
||||
}
|
||||
#define SWIG_exception(a,b) { _SWIG_exception(jenv, a,b); }
|
||||
%}
|
||||
#endif // SWIGJAVA
|
||||
|
||||
/* exception.i ends here */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue