summaryrefslogtreecommitdiff
path: root/libjava/testsuite/libjava.jni/throwit.c
blob: 34a3ca0767673c737e3fd3ac95cd3265c7c70e5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdlib.h>
#include <throwit.h>

JNIEXPORT void JNICALL
Java_throwit_throwit (JNIEnv *env, jclass klass, jstring name,
		      jboolean is_new)
{
  const char *buf = (*env)->GetStringUTFChars (env, name, NULL);
  jclass k = (*env)->FindClass (env, buf);
  (*env)->ReleaseStringUTFChars (env, name, buf);

  if (k == NULL || (*env)->ExceptionCheck (env))
    return;

  if (is_new)
    (*env)->ThrowNew (env, k, "the word is zardoz");
  else
    {
      jmethodID id = (*env)->GetMethodID (env, k, "<init>",
					  "(Ljava.lang.String;)V");
      jstring z = (*env)->NewStringUTF (env, "zardoz is the word");
      jobject obj = (*env)->NewObject (env, k, id, z);
      (*env)->Throw (env, obj);
    }
}