Skip to content

Exception support #757

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

Closed
dcharkes opened this issue Sep 26, 2022 · 1 comment
Closed

Exception support #757

dcharkes opened this issue Sep 26, 2022 · 1 comment
Labels
lang-java Related to Java support

Comments

@dcharkes
Copy link
Collaborator

It would be nice that if a Java exception is throw, it is wrapped in a JavaException in Dart and that Dart exception is throw.

JavaException should contain as much information as possible.

JavaException should not refer to any Java object, but copy all information to Dart memory. (The error message, the Java stack trace, etc.) Exceptions should not be common, so we should not worry about the overhead of copying, and it would be good to not have to worry about native resource management at all.

JavaException should have a toString() that prints the Java error message and stack trace. This will ensure that if we don't catch it we can get some useful information from stderr/stdout.

Related issues:

@dcharkes dcharkes added the lang-java Related to Java support label Sep 26, 2022
@mahesh-hegde
Copy link
Contributor

I think getting the stack trace involves the following calls, as tried on JShell

jshell> var out = new ByteArrayOutputStream()
out ==>

jshell> var print = new PrintStream(out)
print ==> java.io.PrintStream@4520ebad

jshell> var random = new Random()
random ==> java.util.Random@d2cc05a

jshell> try {
   ...>     random.nextInt(-1);
   ...> } catch (Exception e) {
   ...>     e.printStackTrace(print);
   ...> }

jshell> out
out ==> java.lang.IllegalArgumentException: bound must be positive
        at java.base/java.util.Random.nextInt(Random.java:388)
        at do_it$(java:6)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at jdk.jshell/jdk.jshell.execution.DirectExecutionControl.invoke(DirectExecutionControl.java:209)
        at jdk.jshell/jdk.jshell.execution.RemoteExecutionControl.invoke ... tionControlForwarder.commandLoop(ExecutionControlForwarder.java:262)
        at jdk.jshell/jdk.jshell.execution.Util.forwardExecutionControl(Util.java:76)
        at jdk.jshell/jdk.jshell.execution.Util.forwardExecutionControlAndIO(Util.java:137)
        at jdk.jshell/jdk.jshell.execution.RemoteExecutionControl.main(RemoteExecutionControl.java:70)

@HosseinYousefi HosseinYousefi transferred this issue from dart-archive/jnigen Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang-java Related to Java support
Projects
None yet
Development

No branches or pull requests

2 participants