Hi Everyone,

I noticed something today while trying to call some Java code that
generates exceptions and catch them in a JS catch-block. It seems that
an exception thrown from Java code that is called by JS code presents
differently than an exception thrown directly by JS code, even if it
is the same exception. This (unless I am mistaken) forces you to write
code like the following:

try {
    // ... code that throws a FooException, maybe during a call into
Java code, maybe not
}
catch(e if e instanceof FooException || e.javaException instanceof
FooException) {
    e = e.javaException || e

    // code to deal with a FooException
}

while I think someone in this situation would much prefer to write:

try {
    // ... code that throws a FooException, maybe during a call into
Java code, maybe not
}
catch(e if e instanceof FooException) {
    // code to deal with a FooException
}

This is a pretty leaky abstraction. Is there some reason that a Java
exception is wrapped differently based on whether it comes from actual
Java code or not? To anyone trying to use Rhino as a general purpose
application language that is interoperable with Java libraries this
seems like a significant pitfall.

Would the Rhino team be opposed to a context flag that changes the
behavior of ScriptRuntime.newCatchScope to throw exceptions
consistently no matter the language of origination? I would be glad to
write the code myself if it stands some chance of being incorporated
into the trunk.

Thanks,
Ben Reesman
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to