Skip to content

Commit c22415e

Browse files
committed
catch_unwind should NOT be undefined for foreign exceptions; also document possible abort in JoinHandle
1 parent 4a8fe8c commit c22415e

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Diff for: library/std/src/panic.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -311,18 +311,19 @@ where
311311
///
312312
/// # Notes
313313
///
314-
/// This function **might not catch all panics** in Rust. A panic in Rust is not
315-
/// always implemented via unwinding, but can be implemented by aborting the
316-
/// process as well. This function *only* catches unwinding panics, not those
317-
/// that abort the process.
314+
/// This function **cannot** catch panics when `panic=abort`, or with a manually written panic
315+
/// handler that aborts the process.
318316
///
319317
/// If a custom panic hook has been set, it will be invoked before the panic is
320318
/// caught, before unwinding.
321319
///
322320
/// Although unwinding into Rust code with a foreign exception (e.g. an
323-
/// exception thrown from C++ code) via an appropriate ABI (e.g. `"C-unwind"`)
324-
/// is permitted, catching such an exception using this function is undefined
325-
/// behavior.
321+
/// exception thrown from C++ code, or a `panic!` in Rust code compiled or linked with a different
322+
/// runtime) via an appropriate ABI (e.g. `"C-unwind"`) is permitted, catching such an exception
323+
/// using this function will have one of two behaviors, and it is unspecified which will occur:
324+
///
325+
/// * The process aborts.
326+
/// * The function returns a `Result::Err` containing an opaque type.
326327
///
327328
/// Finally, be **careful in how you drop the result of this function**.
328329
/// If it is `Err`, it contains the panic payload, and dropping that may in turn panic!

Diff for: library/std/src/thread/mod.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,7 @@ impl<T> JoinHandle<T> {
17391739
/// operations that happen after `join` returns.
17401740
///
17411741
/// If the associated thread panics, [`Err`] is returned with the parameter given
1742-
/// to [`panic!`].
1742+
/// to [`panic!`] (though see the Notes below).
17431743
///
17441744
/// [`Err`]: crate::result::Result::Err
17451745
/// [atomic memory orderings]: crate::sync::atomic
@@ -1761,6 +1761,16 @@ impl<T> JoinHandle<T> {
17611761
/// }).unwrap();
17621762
/// join_handle.join().expect("Couldn't join on the associated thread");
17631763
/// ```
1764+
///
1765+
/// # Notes
1766+
///
1767+
/// This function has the same minimal guarantee regarding "foreign" unwinding operations (e.g.
1768+
/// an exception thrown from C++ code, or a `panic!` in Rust code compiled or linked with a
1769+
/// different runtime) as [`catch_unwind`]; namely, catching such an exception using this
1770+
/// function will have one of two behaviors, and it is unspecified which will occur:
1771+
///
1772+
/// * The process aborts.
1773+
/// * The function returns a `Result::Err` containing an opaque type.
17641774
#[stable(feature = "rust1", since = "1.0.0")]
17651775
pub fn join(self) -> Result<T> {
17661776
self.0.join()

0 commit comments

Comments
 (0)