4 ms·
Why not eschew the idea of "exceptions" at all then, and just return an error outcome if it can be expected? You've just wrote down a way to do that with no ABI
by nine_k 9y ago
Why not eschew the idea of "exceptions" at all then, and just return an error outcome if it can be expected? You've just wrote down a way to do that with no ABI changes.
A more expensive (and preferably non-allocating) mechanism could be used for a controlled "panic", that is, winding things down in an orderly manner when an unpredictable error occurs.
- mastax 9y agoIt seems a bit like the difference between async fn foo() -> int and fn foo() -> Async<int> (pseudo-rust syntax but the distinction also applies to C# and JS, et. al.) Async code and error handing can both be implented with regular code, but there are cases where some compiler magic can be more elegant, more expressive, or more performant. In these cases it's nice to have a construct that distinguishes this magic from regular values, rather than just making a specific return type magic, IMO. In the throwing values proposal, the magic is to make a regular value usable in exceptions, and also to use mostly-hidden CPU state (flags register) to indicate the type of the value. This allows the C++ proposal to use less memory and perhaps be more performant than rust-style error values. (This ABI change could also be used in other languages like Rust, as mentioned at the end of the document)