3 ms·
That is so repetitive to handle errors. Doesn't go have a cleaner way of handling errors than making the code look far less readable without unified error handl
by h1d 8y ago
That is so repetitive to handle errors. Doesn't go have a cleaner way of handling errors than making the code look far less readable without unified error handling like exceptions?
- IshKebab 8y agoIt is a little repetitive. The best solution is Rust's Result system. But I'd say Ho's error handling system is second to that. You might be thinking "but... exceptions!". They are a pretty bad solution. The problems are: * Error handling is hidden - it's impossible in most implementations to know which exceptions can be thrown by a function * Flow control context is lost. If you wrap lots of lines with try {} you don't know which one caused the error and can't add context information. You end up with shit error messages like "file not found" rather than "error opening config file foo.cfg: file not found". The solution is to wrap every line in a separate try/catch but that is just Go-style error handling but shitter and even more verbose. Go is a good balance. If you want proper error handling you have to actually write it. Yes it is a little tedious but that's what it takes to do it properly. If you don't want to do it properly then fine, use Bash and set -e. But accept that it will be shit.