Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We just code utility methods for each of the types of exceptions we want to throw. Here are some examples:</p> <pre><code>jint throwNoClassDefError( JNIEnv *env, char *message ) { jclass exClass; char *className = "java/lang/NoClassDefFoundError"; exClass = (*env)-&gt;FindClass( env, className); if (exClass == NULL) { return throwNoClassDefError( env, className ); } return (*env)-&gt;ThrowNew( env, exClass, message ); } jint throwNoSuchMethodError( JNIEnv *env, char *className, char *methodName, char *signature ) { jclass exClass; char *exClassName = "java/lang/NoSuchMethodError" ; LPTSTR msgBuf; jint retCode; size_t nMallocSize; exClass = (*env)-&gt;FindClass( env, exClassName ); if ( exClass == NULL ) { return throwNoClassDefError( env, exClassName ); } nMallocSize = strlen(className) + strlen(methodName) + strlen(signature) + 8; msgBuf = malloc( nMallocSize ); if ( msgBuf == NULL ) { return throwOutOfMemoryError ( env, "throwNoSuchMethodError: allocating msgBuf" ); } memset( msgBuf, 0, nMallocSize ); strcpy( msgBuf, className ); strcat( msgBuf, "." ); strcat( msgBuf, methodName ); strcat( msgBuf, "." ); strcat( msgBuf, signature ); retCode = (*env)-&gt;ThrowNew( env, exClass, msgBuf ); free ( msgBuf ); return retCode; } jint throwNoSuchFieldError( JNIEnv *env, char *message ) { jclass exClass; char *className = "java/lang/NoSuchFieldError" ; exClass = (*env)-&gt;FindClass( env, className ); if ( exClass == NULL ) { return throwNoClassDefError( env, className ); } return (*env)-&gt;ThrowNew( env, exClass, message ); } jint throwOutOfMemoryError( JNIEnv *env, char *message ) { jclass exClass; char *className = "java/lang/OutOfMemoryError" ; exClass = (*env)-&gt;FindClass( env, className ); if ( exClass == NULL ) { return throwNoClassDefError( env, className ); } return (*env)-&gt;ThrowNew( env, exClass, message ); } </code></pre> <p>That way, it's easy to find them, your code-completion editor will help you to type them in, and you can pass simple parameters.</p> <p>I'm sure you could expand this to handle chained exceptions, or other more complicated approaches. This was enough to meet our needs.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload