Code Monkey home page Code Monkey logo

Comments (5)

jrobsonchase avatar jrobsonchase commented on May 29, 2024 3

from jni-rs.

dmitry-timofeev avatar dmitry-timofeev commented on May 29, 2024 1

That's a good question because this thing is tricky to handle properly. We ended up with the following (@DarkEld3r, please correct me if I'm wrong):

  • If a native function panics -- throw a Java runtime exception.
  • If a native function returns Err:
    • check if there is a pending (= already thrown) Java exception, do nothing if that's the case.
    • otherwise -- throw a proper Java exception to let the caller know about the error.
  • If a native function returns Ok: return to the Java side.

I can't say if this library can help with handling panics and errors, or simplify it.

from jni-rs.

jrobsonchase avatar jrobsonchase commented on May 29, 2024 1

There's nothing in this lib as of right now that can help with that, but it could be possible with the help of some macro magic.

Some time ago, I played around with wrapping the wren in Rust and came up with a macro system for doing some extra automatic translation of wren types -> rust types and adding safety wrappers. Example here.

Something similar could conceivably be included here if someone had the motivation to build it 😉

Edit: on second look, it doesn't appear that I ever got around to wrapping everything in a panic catch in my wren crate, but it wouldn't be hard to add.

from jni-rs.

onelson avatar onelson commented on May 29, 2024

OK, that makes some good sense.

I suppose I could aim to document this with a const BOOL_NOPE: u8 = 255; and just return BOOL_NOPE in these situations.

I was just wondering if there was some way to model the throwing of the exception in the function signature (like you might with a Result).

from jni-rs.

jrobsonchase avatar jrobsonchase commented on May 29, 2024

I think the question here has effectively been answered, and I filed an enhancement issue for some of the ergonomics improvements proposed here, so I'm closing this one.

Feel free to discuss more ergonomics improvements in #80!

from jni-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.