Skip to content

Commit a2e02c9

Browse files
committed
Handle Java exceptions thrown in calls from C, printing and aborting
Closes #23.
1 parent 38853aa commit a2e02c9

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

java_strings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,12 @@ def native_c_map_trait(self, struct_name, field_vars, flattened_field_vars, fiel
854854
else:
855855
out_c = out_c + ", " + arg_info.arg_name
856856
out_c = out_c + ");\n"
857+
858+
out_c += "\tif ((*env)->ExceptionCheck(env)) {\n"
859+
out_c += "\t\t(*env)->ExceptionDescribe(env);\n"
860+
out_c += "\t\t(*env)->FatalError(env, \"A Java interface method called from rust threw an exception.\");\n"
861+
out_c += "\t}\n"
862+
857863
if fn_line.ret_ty_info.arg_conv is not None:
858864
out_c += "\t" + fn_line.ret_ty_info.arg_conv.replace("\n", "\n\t") + "\n"
859865
out_c += "\t" + self.deconstruct_jenv().replace("\n", "\n\t").strip() + "\n"

0 commit comments

Comments
 (0)