calling exception.printStackTrace() from JNI

前端 未结 2 1941
孤独总比滥情好
孤独总比滥情好 2021-01-26 00:29

The problem is to find out which Java functions call some JNI function. In Java, this would be achieved with new Exception.printStackTrace(), but this must be done

2条回答
  •  没有蜡笔的小新
    2021-01-26 01:12

    By the way, you are able to throw an exception from native layer to Java:) Something like this:

    jint throwOutOfMemoryError( JNIEnv *env, char *message ){
        jclass       exClass;
        char *className = "java/lang/OutOfMemoryError" ;
    
        exClass = (*env)->FindClass( env, className );
        if ( exClass == NULL ){
            return throwNoClassDefError( env, className );
        }
        return (*env)->ThrowNew( env, exClass, message );
    }
    

    Or if you have an instance of Exception, just throw it into Java layer, and then get a stack trace in Java.

提交回复
热议问题