this post was submitted on 18 Dec 2025
258 points (98.9% liked)
Programmer Humor
39521 readers
336 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 6 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Not really, because rust doesn't have exceptions. Instead you are encouraged to handle every possible case with pattern matching. For example:
Option is a type which can either be some 8bit unsigned integer, or none. It's conceptually similar to a
Nullable<int>in C#.In C# you could correctly implement this like:
In rust, you can call Unwrap on an option to get the underlying value, but it will panic if the value is None (because None isn't a u8):
In some cases unwrap could be useful if you don't care about a panic or if you know the value can't be
None. Sometimes it's just used as a shortcut. You can likewise do this in C#:But this throws an exception if number is null.
A panic isn't the same as an exception though, you can't 'catch' a panic, it's unrecoverable and the program will terminate more-or-less immediately.
Rust provides a generic type
Result<T, E>, T being a successful result and E being some error type, which you are encouraged to use along with pattern matching to make sure all cases are handled.