aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/native/NewtCommon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/native/NewtCommon.c')
-rw-r--r--src/newt/native/NewtCommon.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/newt/native/NewtCommon.c b/src/newt/native/NewtCommon.c
index 8b64ec37f..353dcb46f 100644
--- a/src/newt/native/NewtCommon.c
+++ b/src/newt/native/NewtCommon.c
@@ -1,6 +1,23 @@
#include "NewtCommon.h"
+static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException";
+static jclass runtimeExceptionClz=NULL;
+
+void NewtCommon_init(JNIEnv *env) {
+ if(NULL==runtimeExceptionClz) {
+ jclass c = (*env)->FindClass(env, ClazzNameRuntimeException);
+ if(NULL==c) {
+ _FatalError(env, "NEWT X11Window: can't find %s", ClazzNameRuntimeException);
+ }
+ runtimeExceptionClz = (jclass)(*env)->NewGlobalRef(env, c);
+ (*env)->DeleteLocalRef(env, c);
+ if(NULL==runtimeExceptionClz) {
+ _FatalError(env, "NEWT X11Window: can't use %s", ClazzNameRuntimeException);
+ }
+ }
+}
+
jchar* NewtCommon_GetNullTerminatedStringChars(JNIEnv* env, jstring str)
{
jchar* strChars = NULL;
@@ -11,3 +28,15 @@ jchar* NewtCommon_GetNullTerminatedStringChars(JNIEnv* env, jstring str)
return strChars;
}
+void NewtCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...)
+{
+ char buffer[512];
+ va_list ap;
+
+ va_start(ap, msg);
+ vsnprintf(buffer, sizeof(buffer), msg, ap);
+ va_end(ap);
+
+ (*env)->ThrowNew(env, runtimeExceptionClz, buffer);
+}
+