From d048188454e25921dc49aa8692f4bc1fc4f0e7f8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 16 Sep 2003 20:46:22 +0000 Subject: [PATCH] Fixes for throwing exceptions in director (Java) methods Removed redundant ExceptionClear calls git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5113 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/java.cxx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 3160cd17f..8b17d1f85 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1051,11 +1051,14 @@ class JAVA : public Language { Printf(f->code, " jenv->%s(jcls, __SWIG_director_methids[%d], %s);\n", upcall_method, director_methoff, director_uargs); - if (!recursive_upcall) { + if (!recursive_upcall) Printf(f->code, " director->__clear_ricochet(%d);\n", director_methoff); + + Printf(f->code, "if (jenv->ExceptionOccurred()) return $null;\n"); + + if (!recursive_upcall) { Printf(f->code, " } else {\n"); - Printf(f->code, " jenv->ExceptionClear();\n"); if (!pure_virtual) { Printf(f->code, " SWIG_JavaThrowException(jenv, SWIG_JavaDirectorRicochet,\n"); Printf(f->code, " \"Recursive loop into director method %s::%s detected.\");\n", @@ -2688,7 +2691,6 @@ class JAVA : public Language { Delete(super_call); } } else { - Printf(w->code, "jenv->ExceptionClear();\n"); Printf(w->code, "SWIG_JavaThrowException(jenv, SWIG_JavaDirectorPureVirtual,\n"); Printf(w->code, " \"Attempted to invoke pure virtual method %s::%s.\");\n", c_classname, name); @@ -2921,6 +2923,8 @@ class JAVA : public Language { dirclassname, classmeth_off); } + Printf(w->code, "if (jenv->ExceptionOccurred()) return $null;\n"); + if (!is_void) { String *jresult_str = NewString("jresult"); String *result_str = NewString("result"); @@ -2947,7 +2951,6 @@ class JAVA : public Language { if (!recursive_upcall) { Printf(w->code, "} else {\n"); - Printf(w->code, " jenv->ExceptionClear();\n"); Printf(w->code, " SWIG_JavaThrowException(jenv, SWIG_JavaDirectorRicochet,\n"); Printf(w->code, " \"Recursive loop into director method %s::%s detected.\");\n", c_classname, name); @@ -3198,7 +3201,6 @@ class JAVA : public Language { Printf(w->code, " } else\n"); Printf(w->code, " __override[i] = false;\n"); Printf(w->code, "}\n"); - Printf(w->code, "jenv->ExceptionClear();\n"); } Printf(f_directors_h, "};\n\n");