From 5ad9ff5f827b738c7a594af9c82e49793ea4c4dd Mon Sep 17 00:00:00 2001 From: Craig Macdonald Date: Wed, 8 Nov 2023 10:35:29 +0000 Subject: [PATCH 1/5] WIP - java exception printing --- jnius/jnius_export_class.pxi | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jnius/jnius_export_class.pxi b/jnius/jnius_export_class.pxi index a688e2b0..18aab1a7 100644 --- a/jnius/jnius_export_class.pxi +++ b/jnius/jnius_export_class.pxi @@ -14,6 +14,12 @@ class JavaException(Exception): self.stacktrace = stacktrace Exception.__init__(self, message) + def __repr__(self): + ''' + Override __repr__ so that we can see the Java stacktrace + ''' + return super(Exception).__repr__() + '\n' + '\n\t'.join(self.stacktrace) + cdef class JavaObject(object): '''Can contain any Java object. Used to store instance, or whatever. From 7f16ffa94652c579c20eae2eea79e03c0213bd50 Mon Sep 17 00:00:00 2001 From: Craig Macdonald Date: Wed, 8 Nov 2023 10:47:24 +0000 Subject: [PATCH 2/5] try str instead --- jnius/jnius_export_class.pxi | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/jnius/jnius_export_class.pxi b/jnius/jnius_export_class.pxi index 18aab1a7..bb954989 100644 --- a/jnius/jnius_export_class.pxi +++ b/jnius/jnius_export_class.pxi @@ -14,11 +14,14 @@ class JavaException(Exception): self.stacktrace = stacktrace Exception.__init__(self, message) - def __repr__(self): + def __str__(self): ''' - Override __repr__ so that we can see the Java stacktrace + Override __str__ so that we can see the Java stacktrace ''' - return super(Exception).__repr__() + '\n' + '\n\t'.join(self.stacktrace) + rtr = super(Exception).__str__() + if self.stacktrace is not None: + rtr += '\n' + '\n\t'.join(self.stacktrace) + return rtr cdef class JavaObject(object): From b015ea3a71d90b66183a7d83dd720fe4ce167808 Mon Sep 17 00:00:00 2001 From: Craig Macdonald Date: Wed, 8 Nov 2023 10:59:42 +0000 Subject: [PATCH 3/5] change reporting of Java exception name to be more java-like --- jnius/jnius_utils.pxi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jnius/jnius_utils.pxi b/jnius/jnius_utils.pxi index ef5d6ab9..0d8c7400 100644 --- a/jnius/jnius_utils.pxi +++ b/jnius/jnius_utils.pxi @@ -76,7 +76,7 @@ cdef void check_exception(JNIEnv *j_env) except *: j_env[0].DeleteLocalRef(j_env, e_msg) j_env[0].DeleteLocalRef(j_env, exc) - raise JavaException('JVM exception occurred: %s' % (pymsg + " " + str(pyexcclass) if pymsg is not None else pyexcclass), pyexcclass, pymsg, pystack) + raise JavaException('JVM exception occurred: %s' % (str(pyexcclass) + ":" + pymsg if pymsg is not None else pyexcclass), pyexcclass, pymsg, pystack) cdef void _append_exception_trace_messages( From 46e2cce8dc5d105f0ebb3b8eeb6ba5bf9774055c Mon Sep 17 00:00:00 2001 From: Craig Macdonald Date: Wed, 8 Nov 2023 10:59:58 +0000 Subject: [PATCH 4/5] use args[0] for the message --- jnius/jnius_export_class.pxi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jnius/jnius_export_class.pxi b/jnius/jnius_export_class.pxi index bb954989..c7ab5adb 100644 --- a/jnius/jnius_export_class.pxi +++ b/jnius/jnius_export_class.pxi @@ -18,7 +18,7 @@ class JavaException(Exception): ''' Override __str__ so that we can see the Java stacktrace ''' - rtr = super(Exception).__str__() + rtr = self.args[0] if self.stacktrace is not None: rtr += '\n' + '\n\t'.join(self.stacktrace) return rtr From 0ab3a8c939720b972cd156460b97b5d848e009a8 Mon Sep 17 00:00:00 2001 From: Craig Macdonald Date: Wed, 8 Nov 2023 11:39:03 +0000 Subject: [PATCH 5/5] address spacing --- jnius/jnius_utils.pxi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jnius/jnius_utils.pxi b/jnius/jnius_utils.pxi index 0d8c7400..381d4b05 100644 --- a/jnius/jnius_utils.pxi +++ b/jnius/jnius_utils.pxi @@ -76,7 +76,7 @@ cdef void check_exception(JNIEnv *j_env) except *: j_env[0].DeleteLocalRef(j_env, e_msg) j_env[0].DeleteLocalRef(j_env, exc) - raise JavaException('JVM exception occurred: %s' % (str(pyexcclass) + ":" + pymsg if pymsg is not None else pyexcclass), pyexcclass, pymsg, pystack) + raise JavaException('JVM exception occurred: %s' % (str(pyexcclass) + ": " + pymsg if pymsg is not None else pyexcclass), pyexcclass, pymsg, pystack) cdef void _append_exception_trace_messages(