@@ -496,22 +496,33 @@ javaclassname(class::Symbol) = replace(string(class), "."=>"/")
496
496
javaclassname (class:: AbstractString ) = replace (class, " ." => " /" )
497
497
javaclassname (:: Type{T} ) where T <: AbstractVector = JavaCall. signature (T)
498
498
499
+ function _notnull_assert (ptr)
500
+ isnull (ptr) && throw (JavaCallError (" Java Exception thrown, but no details could be retrieved from the JVM" ))
501
+ end
502
+
503
+ function get_exception_string (jthrow)
504
+ jthrowable = JNI. FindClass (" java/lang/Throwable" )
505
+ _notnull_assert (jthrowable)
506
+
507
+ tostring_method = JNI. GetMethodID (jthrowable, " toString" , " ()Ljava/lang/String;" )
508
+ _notnull_assert (tostring_method)
509
+
510
+ res = JNI. CallObjectMethodA (jthrow, tostring_method, Int[])
511
+ _notnull_assert (res)
512
+
513
+ return unsafe_string (JString (res))
514
+ end
499
515
500
516
function geterror ()
501
517
isexception = JNI. ExceptionCheck ()
502
518
503
519
if isexception == JNI_TRUE
504
520
jthrow = JNI. ExceptionOccurred ()
505
- isnull (jthrow) && throw ( JavaCallError ( " Java Exception thrown, but no details could be retrieved from the JVM " ) )
521
+ _notnull_assert (jthrow)
506
522
try
507
523
JNI. ExceptionDescribe () # Print java stackstrace to stdout
508
- jclass = JNI. FindClass (" java/lang/Throwable" )
509
- isnull (jclass) && throw (JavaCallError (" Java Exception thrown, but no details could be retrieved from the JVM" ))
510
- jmethodId= JNI. GetMethodID (jclass, " toString" , " ()Ljava/lang/String;" )
511
- isnull (jmethodId) && throw (JavaCallError (" Java Exception thrown, but no details could be retrieved from the JVM" ))
512
- res = JNI. CallObjectMethodA (jthrow, jmethodId, Int[])
513
- isnull (res) && throw (JavaCallError (" Java Exception thrown, but no details could be retrieved from the JVM" ))
514
- msg = unsafe_string (JString (res))
524
+
525
+ msg = get_exception_string (jthrow)
515
526
throw (JavaCallError (string (" Error calling Java: " , msg)))
516
527
finally
517
528
JNI. ExceptionClear ()
0 commit comments