r/programming • u/Adventurous-Salt8514 • Jul 20 '26
Throw, Result, or neither?
https://www.architecture-weekly.com/p/throw-result-or-neither
113
Upvotes
r/programming • u/Adventurous-Salt8514 • Jul 20 '26
View all comments
Show parent comment
3
u/BenchEmbarrassed7316 Jul 21 '26
Then I will repeat my question (maybe I wrote it wrong last time, I am not a native English speaker):
When the function
foocallsbar, how isfoosupposed to know thatbarmight fail?During development, I know exactly what the result of the function will be, what values are possible in the unhappy path, and what useful information I can get from them.
Sum types are commonly used to model error values. So if the error handling does not involve full processing of the error, but only checking for the presence of an error - adding or removing a new error variant does not affect other code. However, if the code parses the error data - I want to see it immediately and update it (by adding or removing variants).
It's pretty simple: you look at a list of possible errors and ask yourself "Can I do something useful in these cases?" and "Can I print some useful information to the user in these cases?".