diff options
author | Sven Gothel <[email protected]> | 2019-12-06 08:36:19 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-12-06 08:36:19 +0100 |
commit | ddc29141207d9c69f8558265a464cdc4bc014d65 (patch) | |
tree | bf35b8c4de7b63cd5290fb5e14ec8bd49768dc66 /src/newt/native/NewtCommon.c | |
parent | de13e49aadd4b4df09eb1ab37c84cda404586ba5 (diff) |
Bug 1412 - JNI: NEWT Check & Handle Exception after calling back into Java (X11Display + X11Window)
Diffstat (limited to 'src/newt/native/NewtCommon.c')
-rw-r--r-- | src/newt/native/NewtCommon.c | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/newt/native/NewtCommon.c b/src/newt/native/NewtCommon.c index ec10b2da5..e419cb742 100644 --- a/src/newt/native/NewtCommon.c +++ b/src/newt/native/NewtCommon.c @@ -71,24 +71,51 @@ void NewtCommon_FatalError(JNIEnv *env, const char* msg, ...) } } -void NewtCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...) +static void NewtCommon_throwNewRuntimeExceptionVA(JNIEnv *env, const char* msg, va_list ap) { char buffer[512]; - va_list ap; if(NULL==_jvmHandle) { NewtCommon_FatalError(env, "NEWT: NULL JVM handle, call NewtCommon_init 1st\n"); return; } + vsnprintf(buffer, sizeof(buffer), msg, ap); + + if(NULL != env) { + (*env)->ThrowNew(env, runtimeExceptionClz, buffer); + } +} + +void NewtCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...) +{ + va_list ap; + if( NULL != msg ) { va_start(ap, msg); - vsnprintf(buffer, sizeof(buffer), msg, ap); + NewtCommon_throwNewRuntimeExceptionVA(env, msg, ap); va_end(ap); + } +} - if(NULL != env) { - (*env)->ThrowNew(env, runtimeExceptionClz, buffer); - } +void NewtCommon_ExceptionCheck0(JNIEnv *env) +{ + if( (*env)->ExceptionCheck(env) ) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + } +} + +void NewtCommon_ExceptionCheck1_throwNewRuntimeException(JNIEnv *env, const char* msg, ...) +{ + va_list ap; + + if( (*env)->ExceptionCheck(env) ) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + va_start(ap, msg); + NewtCommon_throwNewRuntimeExceptionVA(env, msg, ap); + va_end(ap); } } |