Re: Can't find my own exception class via JNI
- From: Gordon Beaton <not@xxxxxxxxx>
- Date: 30 Nov 2005 08:43:30 +0200
On Wed, 30 Nov 2005 04:00:01 GMT, Paul J. Lucas wrote:
> 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.
Where is the class, and what does your classpath contain?
Correct me if I'm wrong, but your findClassOrDie() doesn't appear to
actually return the jclass it is declared to return. Also, it seems to
print the error message and exit unconditionally, without actually
checking whether FindClass() was successful or not. I'd suggest using
ExceptionDescribe() to see the text explaining the reason for failure,
but only when FindClass() fails (i.e. returns NULL or
ExceptionOccurred() is true).
/gordon
--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
.
- Follow-Ups:
- Re: Can't find my own exception class via JNI
- From: Paul J. Lucas
- Re: Can't find my own exception class via JNI
- References:
- Can't find my own exception class via JNI
- From: Paul J. Lucas
- Can't find my own exception class via JNI
- Prev by Date: Re: Java Timer
- Next by Date: Re: mono-thread concurrent modification
- Previous by thread: Can't find my own exception class via JNI
- Next by thread: Re: Can't find my own exception class via JNI
- Index(es):
Relevant Pages
|