Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Configure Rhino not to catch "Java exceptions" in JS try catch block

619 views
Skip to first unread message

Marc Guillemot

unread,
Dec 10, 2008, 5:38:54 AM12/10/08
to
Hi,

when for instance a NullPointerException occurs in method foo of my host
object in a JS code like this one

try
{
...
myHostObject.foo()
...
}
catch (e)
{
// do something
}

the try/catch block will catch it and I won't see that there is a
problem in the Java code of my host object.

It seems to me that it would make sense if users could have the
possibility to configure Rhino to have "Java exceptions" catch in
try/catch block or not. In our case (HtmlUnit) this would allow us to
faster find errors in our host objects.

What do you think?

Cheers,
Marc.
--
Web: http://www.efficient-webtesting.com
Blog: http://mguillem.wordpress.com

Johan Compagner

unread,
Dec 10, 2008, 5:41:43 AM12/10/08
to Marc Guillemot, dev-tech-js-...@lists.mozilla.org
hmm
i think in 1.6RC7 we just have the opposite that those things are not
catched..

But i could be wrong here need to check this

johan

> _______________________________________________
> dev-tech-js-engine-rhino mailing list
> dev-tech-js-...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
>

Marc Guillemot

unread,
Dec 10, 2008, 5:48:51 AM12/10/08
to
Hi Johan,

I don't know how it was in 1.6RC7 (and it fact it doesn't matter for me
anymore).

What's sure is that in head of 1.7R2 (and in head of trunk), MemberBox
uses Context.throwAsScriptRuntimeEx(e) when an InvocationTargetException
occurs. The consequence is that the original expression is wrapped in a
WrappedException which extends EvaluatorException.

Attila Szegedi

unread,
Dec 10, 2008, 6:51:59 AM12/10/08
to Marc Guillemot, dev-tech-js-...@lists.mozilla.org
This seems fragile to me.

In your place, I'd rather somehow build interception around the host
object. I.e. declare an interface for the host objects, and for
purposes of testing wrap it in a java.lang.reflect.Proxy that reports
exceptions into a log. Or use some AOP solution for achieving
essentialy the same functionality.

Attila.

--
home: http://www.szegedi.org
twitter: http://twitter.com/szegedi
weblog: http://constc.blogspot.com

Marc Guillemot

unread,
Dec 10, 2008, 7:03:07 AM12/10/08
to
Attila Szegedi wrote:
> This seems fragile to me.

can you detail why?

> In your place, I'd rather somehow build interception around the host
> object. I.e. declare an interface for the host objects, and for purposes
> of testing wrap it in a java.lang.reflect.Proxy that reports exceptions
> into a log. Or use some AOP solution for achieving essentialy the same
> functionality.

I don't want exceptions to be reported into a log: I want them to come up!

An alternative would be to open MemberBox to allow Rhino users to
configure custom MemberBox instances as getter / setter for some slots.
This way I could have my own implementaion of MemberBox.invoke that
doesn't wrap InvocationTargetException's cause in a ScriptRuntimeException.

0 new messages