3 ms·
I'm glad this issue is getting some attention. I found the "Exceptions are not exceptional" section to capture something I've noticed several times — that code
by Glench 8y ago
I'm glad this issue is getting some attention. I found the "Exceptions are not exceptional" section to capture something I've noticed several times — that code in Python can fail at a huge number of points even in a small function, nevermind the many exceptions that might happen in nested functions, or code we're using from libraries.
We should have language-level mechanisms for being explicit about what's supposed to happen when unexpected situations happen.
- gnahckire 8y ago> that code in Python can fail at a huge number of points even in a small function This is why unit-tests are really important in Python. > We should have language-level mechanisms for being explicit about what's supposed to happen when unexpected situations happen. That's implemented as a try-except block. You're not supposed to catch errors at the low level unless you're explicitly handling them. If there's an error, bubble it up to the main(). Python's try-except can catch classes, sub-classes, and/or groups (tuples) of classes. It's important to categorize your errors.
- wvenable 8y agoI disagree. The locations of the failure don't matter. All these returning errors and propagating them manually is just masturbation. If an error occurs, you only care about where you can restart the entire transaction (whether that be re-issue a network request, re-try writing a file, etc). That might only be in a handful of places in your code; so that is where you put exception handlers. It literally doesn't matter which of the thousands of possible methods up the call stack threw an exception. So why are suddenly so concerned with tracking that everywhere? If I divide by zero, that's probably just a bug in my program. Why am I wasting time dealing with that on every single division expression everywhere? It makes no sense.