--- /dev/null
+use std::thread;
+
+fn main() {
+ spawn_and_join();
+}
+
+// Page 500.
+fn spawn_and_join() {
+ let mut handles = Vec::<thread::JoinHandle<_>>::new();
+ for i in 0..10 {
+ let h =
+ thread::spawn(move || {
+ if i == 5 {
+ panic!("ERROR"); // Simulate an error.
+ }
+ println!("\nHello from thread {}", i);
+ i + 1
+ });
+ handles.push(h);
+ }
+
+ for h in handles {
+ match h.join() {
+ Ok(r) => println!("\nResult: {}", r),
+ Err(err) => println!("\nError: {:?}", err)
+ }
+ }
+}
\ No newline at end of file