throwit.c 712 B

1234567891011121314151617181920212223242526
  1. #include <stdlib.h>
  2. #include <throwit.h>
  3. JNIEXPORT void JNICALL
  4. Java_throwit_throwit (JNIEnv *env, jclass klass, jstring name,
  5. jboolean is_new)
  6. {
  7. const char *buf = (*env)->GetStringUTFChars (env, name, NULL);
  8. jclass k = (*env)->FindClass (env, buf);
  9. (*env)->ReleaseStringUTFChars (env, name, buf);
  10. if (k == NULL || (*env)->ExceptionCheck (env))
  11. return;
  12. if (is_new)
  13. (*env)->ThrowNew (env, k, "the word is zardoz");
  14. else
  15. {
  16. jmethodID id = (*env)->GetMethodID (env, k, "<init>",
  17. "(Ljava.lang.String;)V");
  18. jstring z = (*env)->NewStringUTF (env, "zardoz is the word");
  19. jobject obj = (*env)->NewObject (env, k, id, z);
  20. (*env)->Throw (env, obj);
  21. }
  22. }