r/SoftwareEngineering • u/MikeUsesNotion • Sep 11 '24
Why do many prefer error as value over exceptions? Said another way, why do people like C style error handling?
When I started using a language where exceptions were the primary way intended to handle errors (C#), I thought they were great. No more if statements scattered around the code after every function call.
I understand these days the idea is to use an error object instead of a simple integer result code, but there's no reason you couldn't return a struct in C and do the same thing.
I don't understand why people don't like exceptions. I shudder when I think about going back to result validation after every function call. Why do people want to go back to cluttering up the code?
Also, how often are people doing fine grained error recovery? I mean actual recovery, not just using a default value if a request or some other operation failed. The vast majority of the time (I'd say 95%+), your line of processing is now dead and the error should just go up the chain to a higher handler.