Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dealing with host exceptions #39

Closed
provegard opened this issue Aug 15, 2018 · 5 comments
Closed

Dealing with host exceptions #39

provegard opened this issue Aug 15, 2018 · 5 comments
Assignees

Comments

@provegard
Copy link

I'm having some trouble with host exceptions. Consider the following code:

public class MainEx {
    public static void main(String[] args) {
        Context context = Context.create("js");

        context.getBindings("js").putMember("evil", new Evil());

        String src = "try {\n" +
                "  evil.callMe();\n" +
                "} catch (e) {\n" +
                "  print(e);\n" +
                "  print(e.message);\n" +
                "  print(e.stack);\n" +
                "}";
        context.eval("js", src);
    }

    public static class Evil {
        public void callMe() {
            throw new RuntimeException("boo");
        }
    }
}

It prints:

com.oracle.truffle.api.vm.HostException: boo
undefined
undefined

The problem is that a test framework like Jasmine (and I suppose any other JavaScript code that catches exceptions) tries to access the properties message and stack.

In Nashorn this wasn't a problem, because I could wrap a host exception (I'm in control of nearly all calls from JavaScript) in a custom exception with a getStack method, and getMessage is of course already there. Due to Nashorn's bean-property-access convention, this worked well.

How should I make Graal host exceptions JavaScript compatible?

@provegard
Copy link
Author

Note that I'm not using Nashorn compatibility mode. I probably should, but that'll only solve the message property.

@wirthi
Copy link
Member

wirthi commented Aug 27, 2018

Hi provegard,

thanks for your report. We need to discuss that internally. I currently know of no way to access the original exception from JavaScript code, Truffle always wraps the exception in a HostException what is not overly helpful to you.

CC @chumer

@provegard
Copy link
Author

Thank you!

Note that the fact that there is a HostException that wraps the original exception needs to be an implementation detail; Jasmine calls e.message and e.stack, so exposing the original via something like e.getOriginal() is also not useful.

@wirthi
Copy link
Member

wirthi commented Jan 21, 2019

@woess has pushed a fix to expose the host exception directly. This should solve your problem.

I am closing this, please reopen if the problem persists.

-- Christian

@wirthi wirthi closed this as completed Jan 21, 2019
@provegard
Copy link
Author

In which release?

Do you mean that the code I posted will print message and stack?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants