r/ProgrammingLanguages • u/Savings_Garlic5498 • Feb 23 '26
Error handling for functions with side effects
I've been thinking a lot about error handling since im designing my own language.
I quite like the errors as values approach where a function returns the succesful value or some error value. I find this very intuitive and it seems like a big improvement over exceptions
However, sometimes the point of a function is mainly to produce a side effect like writing to a file or setting an element of a data structure. You do not really care about the result here which i think clashes a bit with the errors as value approach. As far as i know some languages would represent by having the return be a possible error. In a language like go this can simply be ignored. Rust gives a warning if you dont handle such a result and in zig you must capture the result of a function if it returns something. I do not really like these approaches and i think having such a function throw an error makes more sense but i dont really like how this is done on most exception based languages. I quite like the approach that swift takes where it has exceptions with syntactic sugar that you would often find in errors as values based languages.
Im curious to hear how other people feel about error handling for functions that mostly about their side effects so please let me know your thoughts!
View all comments
Show parent comment
2
u/[deleted] Feb 24 '26
[removed] — view removed comment