-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-panicArea: Panicking machineryArea: Panicking machineryA-threadArea: `std::thread`Area: `std::thread`C-bugCategory: This is a bug.Category: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
I tried this code:
use std::{panic::catch_unwind, thread};
fn main() {
let res = catch_unwind(|| {
thread::scope(|scope| {
scope.spawn(|| panic!("my panic message with useful information"));
});
});
let payload = res.unwrap_err();
let message = payload.downcast_ref::<&str>().unwrap();
dbg!(message);
}
I expected to see this happen: the panic payload from the scoped thread should be forwarded to the main thread using panic::resume_unwind
. The payload passed to panic!
inside the scope should be retrievable there, and there should not be any additional panics.
Instead, this happened: a second panic with no link to the original is caused by the thread::scope
implementation, and the payload is a meaningless "a scoped thread panicked" message.
Meta
rustc --version --verbose
:
rustc 1.85.1
beta and nightly also behave like this
Metadata
Metadata
Assignees
Labels
A-panicArea: Panicking machineryArea: Panicking machineryA-threadArea: `std::thread`Area: `std::thread`C-bugCategory: This is a bug.Category: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.