@@ -1186,32 +1186,37 @@ impl fmt::Debug for Thread {
1186
1186
/// the [`Error`](crate::error::Error) trait.
1187
1187
///
1188
1188
/// Thus, a sensible way to handle a thread panic is to either:
1189
- /// 1. `unwrap` the `Result<T>`, propagating the panic
1189
+ ///
1190
+ /// 1. propagate the panic with [`std::panic::resume_unwind`]
1190
1191
/// 2. or in case the thread is intended to be a subsystem boundary
1191
1192
/// that is supposed to isolate system-level failures,
1192
- /// match on the `Err` variant and handle the panic in an appropriate way.
1193
+ /// match on the `Err` variant and handle the panic in an appropriate way
1193
1194
///
1194
1195
/// A thread that completes without panicking is considered to exit successfully.
1195
1196
///
1196
1197
/// # Examples
1197
1198
///
1199
+ /// Matching on the result of a joined thread:
1200
+ ///
1198
1201
/// ```no_run
1199
- /// use std::thread;
1200
- /// use std::fs;
1202
+ /// use std::{fs, thread, panic};
1201
1203
///
1202
1204
/// fn copy_in_thread() -> thread::Result<()> {
1203
- /// thread::spawn(move || { fs::copy("foo.txt", "bar.txt").unwrap(); }).join()
1205
+ /// thread::spawn(|| {
1206
+ /// fs::copy("foo.txt", "bar.txt").unwrap();
1207
+ /// }).join()
1204
1208
/// }
1205
1209
///
1206
1210
/// fn main() {
1207
1211
/// match copy_in_thread() {
1208
- /// Ok(_) => println!("this is fine "),
1209
- /// Err(_ ) => println!("thread panicked" ),
1212
+ /// Ok(_) => println!("copy succeeded "),
1213
+ /// Err(e ) => panic::resume_unwind(e ),
1210
1214
/// }
1211
1215
/// }
1212
1216
/// ```
1213
1217
///
1214
1218
/// [`Result`]: crate::result::Result
1219
+ /// [`std::panic::resume_unwind`]: crate::panic::resume_unwind
1215
1220
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1216
1221
pub type Result < T > = crate :: result:: Result < T , Box < dyn Any + Send + ' static > > ;
1217
1222
0 commit comments