Comments (5)
from jni-rs.
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.
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.
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.
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)
- ReleaseByteArrayElements or any other way to deallocate the arrays HOT 8
- Correct byte array returning HOT 2
- How to handle rust panics correctly? HOT 3
- ThrowNew should accept Option<_>
- call_method overriding class reference (Classloader issue) HOT 5
- Feature request: LocalExecutor HOT 3
- How can I return an int array in a JNI call? HOT 4
- Better InvalidArgList Error HOT 3
- `Error::JavaException`, when `Display`ed, doesn't show the Java exception message HOT 1
- Reduce clone overhead for JavaType HOT 1
- `get_env` should accept JNI version as a parameter, like the C JNI function `GetEnv` does
- pass rust function as implementation for Java object HOT 5
- JavaVM should be Clone HOT 1
- `get_static_field_unchecked` was not updated to use ReturnType in #344
- `{get,set}[_static]_field_unchecked` should be `unsafe`
- How to add elements into an `JObjectArray`? HOT 2
- `JNIStr` should implement `to_str()` and not `Deref` directly to a `CStr`
- How to pass JavaVM from c to rust HOT 2
- `JClass::from`, `JString::from`, `JThrowable::from`, etc. safety HOT 2
- Byte type confusion
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jni-rs.