Rex Kerr
1 min readFeb 24, 2025

--

? is way better than exceptions, though, because your types fully document the error path, and ? documents where the errors can arise. It's like checked exceptions that aren't a gigantic pain. It's not faking exceptions; it's principled error handling.

There are other principles one could adopt. But within the Rust ethos of blending functional principles with wholehearted embrace of mutability, it's perfect. Functional languages typically have beautiful result types that pack correct results and wrong results in a lovely basically-impossible-to-get-wrong format...and then twist themselves into knots trying to make sure that the error can actually escape from the other lovely constructs like sequences and IO and all the rest.

Rust, in contrast, keeps the lovely result values, and just goes: and this is wrong, so here you go, the wrong value. No mess.

But unlike exceptions, you can't forget it! There's so much trouble caused by exceptions leaking through stuff in unexpected ways. No, in Rust you must always think about it, every single time. But just the very tiniest bit, most of the time, just ? to acknowledge, yes, there could have been an error, and I'm going to hand it up to whoever called me.

--

--

Rex Kerr
Rex Kerr

Written by Rex Kerr

One who rejoices when everything is made as simple as possible, but no simpler. Sayer of things that may be wrong, but not so bad that they're not even wrong.

No responses yet