<html>
<head>
<meta content="text/html; charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Le 29/08/11 17:41, Eric Miller a écrit :
<blockquote cite="mid:4E5B50B1.95FD.00E4.0@dfg.ca.gov" type="cite">But,
what is the correct behavior if a pointer argument is null or an
array size is negative? Call abort()? Would that still crash the
JVM?
</blockquote>
<br>
Calling <tt>exit()</tt> has been reported to stop the JVM (I didn't
tested myself). I presume that it is the same for <tt>abort()</tt>.<br>
<br>
Inside a JNI function, if the arguments were provided by the user
who invoked the function from the Java side, the correct behavior is
to throw a Java exception (<tt>NullPointerException</tt> or <tt>IndexOutOfBoundsException</tt>).
JNI functions have a <tt>JNIEnv</tt> argument which allows
interaction with the JVM. So we can throw an exception from JNI code
as below:<br>
<br>
<pre> jclass c = (*env)->FindClass(env, "java/lang/NullPointerException");
if (c) (*env)->ThrowNew(env, c, "<i>Put some error message here.</i>");
return; // We need to exit from the C/C++ function.</pre>
<br>
Of course this apply only to JNI functions. The "normal" C library
uses other mechanisms (typically no check - or if they check, an
error code returned as an <tt>int</tt>).<br>
<br>
Martin<br>
<br>
</body>
</html>