3 ms·
You can look at "if err == nil" and tell what is going on, but who knows which layer of exception handling will catch that "throws".
by xyproto 3y ago
You can look at "if err == nil" and tell what is going on, but who knows which layer of exception handling will catch that "throws".
- threeseed 3y agoIn JVM languages it is easy to know what is catching what. The method type signatures clearly specify what exceptions will be thrown. And the compiler requires you to deliberately handle those exceptions. But I wouldn't consider Java to be the best approach for error handling anyway.
- kaba0 3y agoWhich is the only sane thing in most cases. What can you do inside the helper function of a helper function with an incorrect user data? The only sane place to handle it is n levels up, so bubbling up is the correct default. At least rust has a handy macro for it, but go’s error handling is catastrophic, not a proper sum type, nor some form of propagation… it is literally the bad errno from C burned into the language.
- Aditya_Garg 3y agoIn go, you should manually propagate the errors up by returning them. At the n levels up, you handle the error. It's a bit cumbersome during write time but a life saver during read/debug time.
- kaba0 3y agoSo manually obscuring the control flow/business logic with boilerplate bubbling up is more readable at debug/read time than it being implicitly, trivially there?