eclipsesource / J2V8

Java Bindings for V8
2.55k stars 355 forks source link

Exceptions from Java show up strangely in Javascript? #58

Open djMax opened 9 years ago

djMax commented 9 years ago

I have some JS that calls into Java (to do an HTTP request). On the way BACK, an exception is getting fired from Java (trying to dismiss an alert). This is all fine, but the exception that shows up on the JS side is of type string, not type Error. This seems bad, I can't quite figure out if it's my fault or the engines fault...?

irbull commented 9 years ago

Yes, the exception on the JS side is the string (message) of the Java exception. Since Java exceptions are not V8Objects, I wasn't really sure what to convert them too. Do you have ideas on what you would like to see here? This is one of the parts of J2V8 that I would like to revisit.

On Fri, May 22, 2015 at 8:34 AM, Max Metral notifications@github.com wrote:

I have some JS that calls into Java (to do an HTTP request). On the way BACK, an exception is getting fired from Java (trying to dismiss an alert). This is all fine, but the exception that shows up on the JS side is of type string, not type Error. This seems bad, I can't quite figure out if it's my fault or the engines fault...?

— Reply to this email directly or view it on GitHub https://github.com/eclipsesource/J2V8/issues/58.

R. Ian Bull | EclipseSource Victoria | +1 250 477 7484 http://eclipsesource.com | http://twitter.com/eclipsesource

djMax commented 9 years ago

I would say new Error(javaSideMessage). As for the stack... I'm not sure you can simulate it properly but given current situation it wouldn't be worse if it was blank... But if you could catch the javascript side of the stack that'd be a win. Interleaving native side would be megawin and better than any other engine I've seen. :)

djMax commented 9 years ago

(by new Error() I mean JS error). V8 might even be smart enough to get the JS side stack for you.

jason-parkhurst commented 9 years ago

This causes some issues for me as well since we lose the javascript side stack trace, forcing me to wrap all calls on both sides.

In the jni code perhaps you use something like this to return it as an error object which would hopefully have the JS stack trace: isolate->ThrowException(v8::Exception::Error(v8String));