MCPcopy Create free account
hub / github.com/deviceplug/btleplug / try_block

Function try_block

src/droidplug/jni_utils/exceptions.rs:25–40  ·  view source on GitHub ↗

Attempt to execute a block of JNI code. If the code causes an exception to be thrown, it will be stored in the resulting [`TryCatchResult`] for matching with [`catch`](TryCatchResult::catch).

(
    env: &'b JNIEnv<'a>,
    block: impl FnOnce() -> Result<T, Error>,
)

Source from the content-addressed store, hash-verified

23/// to be thrown, it will be stored in the resulting [`TryCatchResult`] for
24/// matching with [`catch`](TryCatchResult::catch).
25pub fn try_block<'a: 'b, 'b, T>(
26 env: &'b JNIEnv<'a>,
27 block: impl FnOnce() -> Result<T, Error>,
28) -> TryCatchResult<'a, 'b, T> {
29 TryCatchResult {
30 env,
31 try_result: (|| {
32 if env.exception_check()? {
33 Err(Error::JavaException)
34 } else {
35 Ok(block())
36 }
37 })(),
38 catch_result: None,
39 }
40}
41
42impl<'a: 'b, 'b, T> TryCatchResult<'a, 'b, T> {
43 pub fn catch(

Callers 3

start_scanMethod · 0.85
get_poll_resultFunction · 0.85
test_catchFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_catchFunction · 0.68