-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A thread closure's destructor can panic in std::thread::spawn
on Windows
#124468
Comments
@rustbot claim |
What is exactly the problem here? I would expect a panic in the drop impl to unwind out of |
In my particular case, the OS error was caused by spawning threads in What I'm proposing here is catching the panic (not necessarily discarding the panic message) and returning the error. So that the caller can know about both the panic and the OS error. |
Unless you return the panic payload as the error instead of the OS error, the caller would still not be able to see the panic and resume unwinding. |
Maybe I'm missing something specific to stdlib, but I think the panic message is preserved unless a panic hook is declared to suppress it: fn main() {
match std::panic::catch_unwind(|| panic!("Ahhh!")) {
Ok(()) => unreachable!(),
Err(_) => eprintln!("Panic avoided, backtrace preserved!"),
};
} The above prints:
|
The panic hook displays the message (if any) when using |
Thanks for the clarification, I wasn't aware there was more to it. However, |
The following is part of the native
Thread::new
implementation on Windows:If
drop(Box::from_raw(p));
panics, then the error is not returned. I suggest to replace thedrop
statement with:The text was updated successfully, but these errors were encountered: