So, the fourth of July weekend was extremely relaxing; I pretty much just enjoyed the beautiful weather we had all weekend and took some much needed rest. I went home for the weekend to my parents' house and pretty much stayed there the whole weekend with the exception of going to Sandy Hook for a night to watch someone I know play at a local bar. In other words, I haven't done much on this project in the last 3 days or so. However, I have managed to make some progress in the last day since I've been back to work.
Yesterday, I started to turn my attention towards working with exceptions and passing them between Java and Perl. To do this I started implimenting an example using the CNI Perl bindings and creating a SWIG wrapper to a Java class from a GCJH generated C++ header file (wow, that's a mouth full). Luckily, Java and Perl parallel each other rather nicely when it comes to exception handling. My main problem came with how to trigger a 'die' statement from SWIG once a Java exception had been thrown. Generating the propper SWIG statements was easy, there's an '%exception' macro used to wrap wrapped methods. The real problem was trying to figure out how to actually trigger 'die' from the C++. The 'croak' method is available to me in SWIG but it only lets me pass a string, not a pointer to an object. Instead, I decided to do the following: I created a sub 'throw exception { die shift; }' in my Perl test driver. Now when I catch an exception from Java in C++ I use perls' C sub-routine calling interface to call throw_exception and pass it the exception. This is simple enough, although it took me awhile to figure out. There are a few problems here: One, the exception I get in C++ doesn't have a Perl interface so all I can pass to 'throw_exception' is a pointer to something Perl doesn't know about. I have a plan on how to handle this but I'm a little shaky about it. And two, Perl and Java exception information looks very different, how is a user going to debug an exception from this program? This gets trickier when you think about how many layers there are: Perl, C, C++, Class Compiled Java and Natively Compiled Java.
Yesterday, I started to turn my attention towards working with exceptions and passing them between Java and Perl. To do this I started implimenting an example using the CNI Perl bindings and creating a SWIG wrapper to a Java class from a GCJH generated C++ header file (wow, that's a mouth full). Luckily, Java and Perl parallel each other rather nicely when it comes to exception handling. My main problem came with how to trigger a 'die' statement from SWIG once a Java exception had been thrown. Generating the propper SWIG statements was easy, there's an '%exception' macro used to wrap wrapped methods. The real problem was trying to figure out how to actually trigger 'die' from the C++. The 'croak' method is available to me in SWIG but it only lets me pass a string, not a pointer to an object. Instead, I decided to do the following: I created a sub 'throw exception { die shift; }' in my Perl test driver. Now when I catch an exception from Java in C++ I use perls' C sub-routine calling interface to call throw_exception and pass it the exception. This is simple enough, although it took me awhile to figure out. There are a few problems here: One, the exception I get in C++ doesn't have a Perl interface so all I can pass to 'throw_exception' is a pointer to something Perl doesn't know about. I have a plan on how to handle this but I'm a little shaky about it. And two, Perl and Java exception information looks very different, how is a user going to debug an exception from this program? This gets trickier when you think about how many layers there are: Perl, C, C++, Class Compiled Java and Natively Compiled Java.


1 Comments:
Just a quick note to say I really like what you are doing and I'm watching with interest.
I'd be particularly interested in anything that would allow access to Java RMI so that I can use a perl client to access the Hermes ebXML server, and especially interested in being able to use Java classes without the overhead of firing up a JVM.
Good work so far.. hope you have a lot of success.
Post a Comment
<< Home