how to show C line number AND exception type in JNI exception stacktrace?

Discussion in 'Java' started by Elaine Cheong, Dec 8, 2006.

  1. Does anyone know how to display BOTH the C code line number and the Java
    exception type in a JNI exception stack trace in Java? Printing to stdout
    or stderr in C is not sufficient, since I need to display the information
    in a Java GUI dialog box.

    Example:
    In my C code, I call JNI GetMethodID() to get a reference to a Java method
    that doesn't exist. NoSuchMethodError exception is thrown. I am able to
    do one of the following:

    a. In the C code, check for the exception, and return immediately to the
    Java code, where it catches the NoSuchMethodError Throwable object and
    displays the stack trace, which only indicates the Java code line numbers
    and type of the Throwable object. It does not indicate the C code line
    number(s).

    b. In the C code, check for the exception, print out the stack trace
    using ExceptionDescribe(), clear the exception using ExceptionClear(), and
    then creating and throwing my own Throwable object that contains the C
    code line number (using __LINE__) in the error message back to the Java
    code. Is it possible to get the original Throwable object type and error
    message saved into a C data structure w/o crashing the JVM due to calling
    disallowed JNI functions? Otherwise, the Java code does not know which
    one of the following exceptions was thrown:

    - NoSuchMethodError: if the specified method cannot be found.
    - ExceptionInInitializerError: if the class initializer fails due to an
    exception.
    - OutOfMemoryError: if the system runs out of memory.

    If you post to the newsgroup, please also reply to me by email.

    Thanks,
    Elaine
    Elaine Cheong, Dec 8, 2006
    #1
    1. Advertising

  2. Re: how to show C line number AND exception type in JNI exception stack trace?

    On Fri, 8 Dec 2006 14:22:08 -0800, Elaine Cheong wrote:
    > a. In the C code, check for the exception, and return immediately
    > to the Java code, where it catches the NoSuchMethodError Throwable
    > object and displays the stack trace, which only indicates the Java
    > code line numbers and type of the Throwable object. It does not
    > indicate the C code line number(s).


    After detecting the exception in your native code, store the line
    number and other state that might be interesting, then return to Java.

    In your catch block, call a native method to retrieve the stored
    information, then throw a new exception containing the line number and
    the original exception.

    I agree it would be nice if you could catch the exception in C!

    > If you post to the newsgroup, please also reply to me by email.


    I don't do mail, sorry.

    /gordon

    --
    [ don't email me support questions or followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Dec 9, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S. Justin Gengo
    Replies:
    0
    Views:
    716
    S. Justin Gengo
    Aug 5, 2003
  2. Sebastien
    Replies:
    3
    Views:
    8,576
    chinnaswamyg
    Sep 28, 2006
  3. chinnaswamyg
    Replies:
    0
    Views:
    653
    chinnaswamyg
    Sep 28, 2006
  4. Samuel
    Replies:
    3
    Views:
    268
    Samuel
    Jun 22, 2007
  5. Andrew Chen
    Replies:
    11
    Views:
    301
    Kru K.
    Oct 14, 2010
Loading...

Share This Page