Re: Catching exceptions in JPL
[email protected] Wed, 8 Nov 2000 09:11:31 -0500
| Newsgroups | perl.jpl |
|---|---|
| Message-ID | <[email protected]> |
Thanks, Ed. I guess I should have examined the JPL code more closely because I was unaware that ExceptionOccured(), ExceptionDescribe(), and ExceptionClear() existed. I tried a little test and it worked...sort of. The problem is that if the exception occurs in the Java (duh!) then the JPL::AutoLoader fails because it doesn't get a valid ref to bless. This is the point where the Perl dies. So, my exception handling code never has a chance to run because Perl bails out deep within the bowels of JPL. Thanks for the suggestion though. I has me thinking about a possible patch to JPL that will allow exception handling within the JPL::AutoLoader. Cheers, Scott. ==================================================== M. Scott Roth, <[email protected]> Information Systems Engineer Science Applications International Corporation 703-375-2260 ========================<><========================= Ed Chidester <echid@textwi To: [email protected], [email protected] se.com> cc: Subject: Re: Catching exceptions in JPL 11/07/00 04:55 PM Please respond to Ed Chidester > > Does anyone know of a way to catch a Java exception from JPL? For example, > I have a login method in Java that throws an exception if the login fails > for any number of reasons. I have JPL code that calls the login method > from Perl but since the method is a void method, I get no return value to > evaluate for success or failure. The login code is not mine or I would > change it to return a boolean just for this reason. > ... > > Any ideas would be appreciated. Thanks! > You said 'any' ideas, but I'm going to start by saying that this is an incomplete (and possibly wrong) idea... Also, I'm still in the early stages of using JPL Now that my disclaimer is finished, here's my idea: Java's JNI has method calls to catch, describe, and remove Java exceptions from within native code (ExceptionOccurred, ExceptionDescribe, and ExceptionClear respectively). Looking at the JNI/JNI.xs source I see these same methods wrapped in xs code. You might be able to do something like this: use JNI; $username = "me\\you\@thisplace.com"; $login = JPL::AutoLoader::getmeth('login',['java.lang.String'],[]); &$login($username); if ( ExceptionOccurred( ) ) { ExceptionDescribe( ); ExceptionClear( ); } Of course, ExceptionOccurred( ) returns an object of type "jthrowable" so I'm not entirely sure how that'll be handled. Hope this helps! Ed. // Edward Chidester // Software Engineer MNIS - Textwise Labs // (315) 426-9311 x232 401 South Salina Street // [email protected] Syracuse, NY 13202