Hello all! I'm looking to provide a very brief and very high level summary of https://github.com/rust-lang/rfcs/pull/2945 on this week's "This Week in Rust" podcast. Does this summary sound accurate?
Even though Rust does not implement exceptions the way languages like Java or C++ do, it does support unwinding under two conditions
1) When rust code panics, it unwinds the stack
2) When Rust is interfacing with another programming language with exceptions, like C++, it can call functions in that language to unwind the stack.
Currently, when foreign code - that means code not written in Rust - invokes Rust code and the Rust code panics and unwinds, the result of that unwind will not be available to the foreign code.
Looking forward to the podcast!
This RFC is somewhat more limited than that; it won't provide a way for Rust to actually access an exception object itself thrown by C++, or for C++ to access a
panic object. The
"C unwind" ABI will simply make it safe to unwind C++ frames with a Rust
panic (or Rust frames with a C++ exception), which some crates are already doing even though it is currently undefined behavior. In order to recover from a
panic and resume normal execution, the
panic must still be caught by Rust, not by C++; similarly, C++ exceptions can only be caught by C++.
Otherwise, that summary seems fairly good, though I'd suggest a few tweaks. We're defining a new ABI string, but not a new ABI per se; also, I would say "throws an exception" rather than "encounters an exception". (You could also combine the first two bullets; it's probably sufficient to define unwinding as "how C++ exceptions and Rust
panics are implemented.")
That is very helpful, thank you!
Last updated: Jan 26 2022 at 08:02 UTC