Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We have a java library (.JAR) that we are consuming in C++ application through JNI, so we are able to call Java class methods from C++. However, we would also like to catch exceptions thrown by the Java methods into our C++ code that is calling the Java methods. How to do this using JNI?

The other challenge we have is we would also like to receive callbacks from Java library into C++. Specifically what we would like to do is - There is an interface in Java, meaning it only has method definitions, no implementation. Now, we want to implement this interface of Java in C++ through JNI, so the methods of the interface will be implemented in C++ code and then the object of the C++ class that implements this interface should be sent as a parameter in a method call from C++ to Java, so this is like registration of callback class from C++ to Java. This way, whenever the Java code needs to send notifications to C++ code, it can call the methods of the C++ registered class. How to achieve this in JNI?

What I have tried:

I can not try but it is possible or not?
Posted
Updated 17-Jun-17 0:12am
Comments
Richard MacCutchan 17-Jun-17 6:08am    
The only way to catch the exceptions would be to have a universal catch all in your Java code. This would then need to capture all the information relating to the exception and call a C++ function to process it.

Not sure about the callbacks but it may be possible; you need to try a few experiments.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900