Comments (3)
Hello! Apologies for not responding sooner, I missed that this issue was added.
Indeed there is not error handling, however, it is very much on my list of things to address. It did not occur to me that this would make applications where an exception is thrown technically unviable.
First, as a lame workaround, you can simply call the underlying JNI methods for checking exceptions. java.lang.Throwable
looks to be a regular class so you could presumably describe it with JNI Bind if you wanted. That obviously isn't very satisfying, but if you're keen to use JNI Bind, this would hopefully unblock you.
Long term, I hope for a the exception syntax to look something like:
static constexpr ::jni::Class kClass {
"kClass",
jni::Method{"Foo", ... }.Throws(kIOException, kEtcException, ... }
};
jni::LocalObject<kClass> obj {};
// obj("Foo", ...); won't compile
jni::Try {
obj.Foo(...);
}.Catch([](jni::LocalObject<kIOException> e) {...})
.Catch(...);
This is still insufficient for cases like FindClass
, and more broadly, if you wanted to check for exceptions every call (where the above syntax is clumsy, but also referring to something slightly different). I didn't do this for the first pass because I didn't understand the performance implications, and taking it away down the road seemed bad.
What I intend to do is to provide a compile time optional pre and post lambda that you can write for all JNI calls. This could be used for things like logging also. I haven't thought deeply enough on how to accomplish this, and I figure it may take a bit of time.
My first priority is resolving existing bugs, but when that's done, I'll look at this next. Resolving this is probably worth gating the 1.0 for. as the syntax will be forever.
Thank you for your interest in JNI Bind!
from jni-bind.
Thanks for the elaborated reply.
I think that an optional post JNI call lambda could allow resolving the most burning issue IMHO, which is avoiding app crash.
I would use that lambda for calling ExceptionCheck()
and throwing a C++ exception in case a Java exception is pending.
The exception syntax in given example looks very neat, but I'm not sure how it would get along with the post JNI call lamda that checks for Java exceptions.
I'll definitely keep an eye on on this library, I'm sure that version 1.0 will be awesome.
from jni-bind.
I fully intend to complete this, however, I think unfortunately I'm going to deprioritize this from the initial release. There is simply too much to do, and this isn't absolutely critical for the tool to work (given we're already using it in prod).
I absolutely agree you should do this, but unfortunately, I just haven't had time to complete this yet.
from jni-bind.
Related Issues (20)
- Calling a method on a class for the first time on a secondary thread fails. HOT 6
- UTF-8 string conversion methods HOT 2
- Fix MSVC compilation failures HOT 1
- jni_mh.h with jint as 32-bit long HOT 9
- Add `Self` syntax documentation
- Attempt to remove non-JNI local reference with GlobalObject HOT 13
- Getting compilation errors when using modules HOT 3
- Generate release header is freezing on macOS HOT 3
- Godbolt Sample
- Introductory Youtube video HOT 1
- Add cmake module file HOT 1
- Difficulty expressing a method call HOT 6
- Update Bazel to version 7.*
- Add Mac test runner HOT 2
- Add per trace logging
- Document `SetFallbackLoader` workaround for Android.
- `std::nullptr_t` should be an acceptable ctor for all `Scoped` types.
- Add enum class support
- Support Inheritance
- `Self` is broken when used in statics
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-bind.