#java #jni #ffi

macro catch_panic_macros

The proc macro impl for catch_panic

1 stable release

1.0.0 Jul 25, 2022

#63 in #jni

Download history 212/week @ 2024-03-13 226/week @ 2024-03-20 58/week @ 2024-03-27 69/week @ 2024-04-03 59/week @ 2024-04-10 44/week @ 2024-04-17 31/week @ 2024-04-24 16/week @ 2024-05-01 112/week @ 2024-05-08 77/week @ 2024-05-15 114/week @ 2024-05-22 33/week @ 2024-05-29 33/week @ 2024-06-05 33/week @ 2024-06-12 28/week @ 2024-06-19 16/week @ 2024-06-26

117 downloads per month
Used in catch_panic

MIT/Apache

6KB
95 lines

⚾ #[catch_panic]

Crates.io Documentation License

A helper macro for safe Java-Rust interop that "catches" Rust panics and rethrows them as Java exceptions.

Getting Started

Add catch_panic as a dependency to your Cargo.toml:

[dependencies]
catch_panic = "1.0.0"

Usage

Attach #[catch_panic] to a JNI callback to have panics converted into RuntimeExceptions:

use jni::JNIEnv;
use catch_panic::catch_panic;

#[no_mangle]
#[catch_panic]
pub extern "C" fn Java_com_example_Example_panic(_env: JNIEnv) {
    panic!("everything is not fine");
}

See the docs for macro options and more information.

License

This crate is dual-licensed under either:

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

The code in this crate is a derivative of code from HermitSocialClub/HermitRepo, specifically the files ProjectTomato/tomato_macros/src/lib.rs and ProjectTomato/tomato/src/util.rs. All authors of these two files have agreed to relicense the original code under the above license.

Dependencies

~1.5MB
~36K SLoC