Created
February 16, 2012 23:10
-
-
Save robinhouston/1848636 to your computer and use it in GitHub Desktop.
Test case for throwing an exception in Java and catching it in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Derived from the example at | |
* http://gcc.gnu.org/onlinedocs/gcj/Invocation.html | |
* | |
* Compile using: | |
* /usr/local/bin/g++ -c unholy.cc | |
* /usr/local/bin/gcj -lstdc++ unholy.o -o unholy | |
*/ | |
#pragma GCC java_exceptions | |
#include <gcj/cni.h> | |
#include <java/io/PrintStream.h> | |
#include <java/lang/Integer.h> | |
#include <java/lang/String.h> | |
#include <java/lang/System.h> | |
#include <java/lang/Throwable.h> | |
#include <iostream> | |
using namespace std; | |
int main(int argc, char** argv) | |
{ | |
try { | |
JvCreateJavaVM(NULL); | |
JvAttachCurrentThread(NULL, NULL); | |
java::lang::String *n = JvNewStringLatin1("23skidoo"); | |
JvInitClass(&java::lang::Integer::class$); | |
java::lang::Integer::parseInt(n); | |
JvDetachCurrentThread(); | |
} | |
catch (java::lang::Throwable* t_p) { | |
cerr << "Unhandled Java Exception:" << endl; | |
t_p->printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment