diff options
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); } } |