Daily Note - 2025-04-10
Hey, I'm Hanno! These are my daily notes on Crosscut, the programming language I'm creating. If you have any questions, comments, or feedback, please get in touch!
I've laid out some design goals for the overall language, and for error handling specifically. From here, I'd like to demonstrate how my design for variant types and automatic lifting can meet those, and why I think that alternative solutions don't do this well enough.
Let's start by looking at error handling in Rust. There, error handling is
done by returning a Result
enum, which can carry a regular value or an error.
If you can't handle an error locally, you usually abort your function and return
an error yourself (often using the ?
operator).
If multiple specific errors can occur in a function, you can convert them into a broader error enum whose variants tell you more about which specific error occurred. Or you can convert any error into a general error value that hides the specific error information, but provides a good error message, using something like Anyhow.
On top of that, there are panics. You can always convert an error into a panic,
for example using the unwrap
method. This makes sense, if you don't want to
deal with error handling right now (when you're prototyping, for example), or to
signal that it's not possible for an error to actually happen in the context of
your code.
Those are the broad strokes. Obviously, this is not a complete reference of error handling in Rust. I just wanted to call out some of its elements so I can refer to them tomorrow, when I'll go into the problems I see with this approach.
Hey, you! Want to subscribe to my daily notes? Just let me know (maybe include a nice message, if you're up for it), and I'll send you an email every time I post a new one.