summaryrefslogtreecommitdiff
path: root/src/handle_unwind.rs
diff options
context:
space:
mode:
authorMica White <botahamec@gmail.com>2024-12-26 12:06:47 -0500
committerMica White <botahamec@gmail.com>2024-12-26 13:23:40 -0500
commit9eec9ab94bbe5c9fbd52d5bbf393fe1ddcc6fc26 (patch)
treea55cb81db2167cd3caf3330d503c2e9cacd24fd4 /src/handle_unwind.rs
parentdc16634f4abdb1e830d2749e64b419740702b302 (diff)
Documentation
Diffstat (limited to 'src/handle_unwind.rs')
-rw-r--r--src/handle_unwind.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/handle_unwind.rs b/src/handle_unwind.rs
index 220d379..42b6fc5 100644
--- a/src/handle_unwind.rs
+++ b/src/handle_unwind.rs
@@ -1,6 +1,9 @@
use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
-/// Runs `try_fn`. If it unwinds, it will run `catch` and then continue unwinding
+/// Runs `try_fn`. If it unwinds, it will run `catch` and then continue
+/// unwinding. This is used instead of `scopeguard` to ensure the `catch`
+/// function doesn't run if the thread is already panicking. The unwind
+/// must specifically be caused by the `try_fn`
pub fn handle_unwind<R, F: FnOnce() -> R, G: FnOnce()>(try_fn: F, catch: G) -> R {
let try_fn = AssertUnwindSafe(try_fn);
catch_unwind(try_fn).unwrap_or_else(|e| {