2 ms·
> Fallability in Rust is spelled "Result<T, E>", and drop does not return one. This isn't really true. All Rust functions that can panic are fallible, independ
by fluffything 7y ago
> Fallability in Rust is spelled "Result<T, E>", and drop does not return one.
This isn't really true. All Rust functions that can panic are fallible, independently of whether their return type is `Result` or not.
There are idioms to use `Result` for recoverable failures and panics for "harder-to-recover" failures, but that's about it, and people do use `catch_unwind` on `main` to make their web-servers live forever, and they are doing it right, IMO (this is one of the many justified usecases of `catch_unwind`).
If the errors would actually be non-recoverable, `catch_unwind` wouldn't need to exist.
Also, even if you think as panics as "errors that will kill this thread", your program has multiple threads, and resources leaked by one thread continues to be leaked (e.g. memory is not reclaimed by the OS until the whole process exits), so you still have a leak.
- steveklabnik 7y ago> This isn't really true. All Rust functions that can panic are fallible, Yes, in the abstract sense of fallible, but not in the terminology of Rust, or how the features are used generally. Defaults and language matter, and we've seen the actual usage follow. I don't ever remember seeing a crate suggest catch_unwind for error handling. > our program has multiple threads, and resources leaked by one thread continues to be leaked Yep, my bad, I simply made a mistake here.