Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Elaine Cheong - 08 Dec 2006 22:22 GMT
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
Gordon Beaton - 09 Dec 2006 08:59 GMT
> 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

Signature

[ 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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.