4 ms·
A bit of topic but: I write a lot of C and lately I've been using 'bool' as my error handling type. This probably sounds stupid to many people, but I'm a minima
by AlexanderDhoore 6y ago
A bit of topic but: I write a lot of C and lately I've been using 'bool' as my error handling type. This probably sounds stupid to many people, but I'm a minimalist. If a function has an error -> return false.
In the past I would have returned an enum or just int with values for every error that could occur. But I realized that I almost never actually handle the error cases differently. I just want to know whether an error did or did not happen.
This style gives me 99% of what I need, and it's so god damn simple.
- izacus 6y agoThat works until you find out that you just wrote one of those godawful pieces of software that say "An error has occured" for everything that goes wrong, including wrong password, network connection issues or simple misconfiguration.
- kortex 6y agoI agree. This sounds pretty awful. I've worked everything from camera drivers to distributed, and I can't think of a single interface I've used where only having a "Something failed" signal wouldn't drive me up a wall debugging. Opening a file is probably the most mundane thing I can think of, and there's at least two situations I want to log/bubble up - file not found vs some other i/o error. Oh, setters and getters I guess return bool works ok.
- tluyben2 6y agoYep, I was integrating a banking API yesterday and every single error just shows ‘Something went wrong, contact support.’. Nothing more; I asked if this was for security (to log and hide the real error as it might give something away), and their answer was ‘kind of’ as they do not have sane errors, just stacktraces logged to Sentry. Incredibly hard to debug (as client we get no access to their Sentry) as you do not know if the authorisation was wrong or some amount was wrong or whatever. And all errors including not found(404) are 500...