Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to show C line number AND exception type in JNI exception stacktrace?

Reply
Thread Tools

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

 
 
Elaine Cheong
Guest
Posts: n/a
 
      12-08-2006
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
 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      12-09-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: When running Ant on command line, how to not-show its WARNING messages and only show ERROR message? Roedy Green Java 5 12-13-2011 05:49 PM
Re: When running Ant on command line, how to not-show its WARNINGmessages and only show ERROR message? Lew Java 0 12-10-2011 01:46 AM
Re: When running Ant on command line, how to not-show its WARNING messages and only show ERROR message? John B. Matthews Java 0 12-09-2011 05:19 PM
Read a file line by line with a maximum number of characters per line Hugo Java 10 10-18-2004 11:42 AM



Advertisments