"Aaron M. Renn" <[EMAIL PROTECTED]> writes:

> >Could someone tell me how we should be wording exception messages?
> >It seems like we should be using something similar to what the GNU
> >coding standard requires, but I'm not sure how applicable it is to
> >Java code, nor how to do all of it in native code (for example, the
> >line number thing...).
> 
> The GNU standard for reporting errors?  These are oriented towards user
> level programs.  I think simply throwing an exception with a text
> description of the problem and context data is good enough.

That's what I'm getting at.  What should the context be, or how should
it be formatted? 

For example when you throw a NullPointerException from native code
(perhaps in one method there are multiple places you may do this) what
would be the best way to denote the problem?

Example 1:

JNIEXPORT jfloat JNICALL Java_java_lang_Float_parseFloat
  (JNIEnv * env, jclass thisClass, jstring s)
{
  const char *nptr;
  char *endptr, *myptr;
  jvalue val;

  if (s == NULL)
  {
    _javalang_ThrowException(env, "java/lang/NullPointerException", "null argument");
    return 0.0;
  }
...

/* Example 2: */
  nptr = (char*)((*env)->GetStringUTFChars(env, s, 0));
  if (nptr == NULL)
  {
    _javalang_ThrowException(env, "java/lang/NullPointerException", "null returned by 
GetStringUTFChars");
    return 0.0;
  }
...

I like having concise representations which convey as much meaning as
possible without being a very long diatribe on what happened to cause
the exception and I'm not completely happy with what I've written
above.  It would be easier to decide what would be the message (and to
have messages from different exceptions appear similar) if there was
some sort of standard we would adhere to (documented).

Sun for example makes the text of a NullPointerException exactly this,
"null".  How informitive.

Brian
-- 
|-------------------------------|Software Engineer
|Brian Jones                    |[EMAIL PROTECTED]
|[EMAIL PROTECTED]                    |http://www.nortel.net
|http://www.classpath.org/      |------------------------------

Reply via email to