Can't find my own exception class via JNI



Given:

jclass findClassOrDie( JNIEnv *env, char const *name ) {
jclass const theClass = env->FindClass( name );
cerr << "FindClass(" << name << ") failed" << endl;
exit( 1 );
}

void throwMyException( JNIEnv *env, char const *msg ) {
static char const MyExceptionClass[] =
"com/mycompany/utils/MyExceptionClass";
env->ThrowNew( findClassOrDie( env, MyExceptionClass ), msg );
}

Any call to throwMyException() and subsequently to findClassOrDie()
always fails because FindClass() never finds MyExceptionClass, but I
have no idea why not. FindClass works fine for standard Java exception
classes like IllegalArgumentException.

So why can't it find my exception class? It's just a simple class
derived from Exception.

- Paul
.



Relevant Pages

  • Re: JNI FindClass problem
    ... While googling this I found people complaining about FindClass ... an exception being thrown before the function returns. ...
    (comp.lang.java.programmer)
  • Re: Cant find my own exception class via JNI
    ... > always fails because FindClass() never finds MyExceptionClass, ... FindClass works fine for standard Java exception ...
    (comp.lang.java.programmer)
  • JNI FindClass problem
    ... I'm trying to locate a Java class from a C++ method using FindClass ... an exception being thrown before the function returns. ...
    (comp.lang.java.programmer)
  • Re: How to create an instance of a class by class name in a string?
    ... The classes have to descend from tPersistent. ... There is also FindClass, ... unlike GetClass it raises an exception if the class isn't registered. ...
    (comp.lang.pascal.delphi.misc)