Re: Catching exceptions in JPL
[email protected] (Ed Chidester) Tue, 7 Nov 2000 16:55:40 -0500 (EST)
| Newsgroups | perl.jpl |
|---|---|
| Message-ID | <[email protected]> |
>
> 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