21 ms·
You can do nearly everything using Python errors. One thing that bothers me a bit, is the amount of text needed to catch them and bubble them up. Depending on t
by atoav 2y ago
You can do nearly everything using Python errors. One thing that bothers me a bit, is the amount of text needed to catch them and bubble them up. Depending on the programming style traditional exceptions may also not be adequately re
For this Rust style error handling can be interesting, eg using poltergeist (https://github.com/alexandermalyga/poltergeist https://github.com/alexandermalyga/poltergeist) or result (https://pypi.org/project/result/ https://pypi.org/project/result/).
- drcongo 2y agoWould you mind explaining what the benefits of either of those libraries is over normal exception handling? The examples at the top of the Result readme seem almost exactly as verbose as each other. I kinda like the idea of a Result object, but it seems like a lot of library imports for no gain so I'm sure I'm missing something.
- benrutter 2y agoNot OP, but as someone who likes this style of exception handling, I really appreciate that it offloads everything to the type system. With normal exceptions, I have to use my meat brain to figure out if I've handled all the exceptions that might come up, whereas mypy can just tell me if I've handled the result object correctly That said, I don't use either library since, in my experience, you need them to be used all the way down the stack to actually get the benefit.
- drcongo 2y agoAhhh, I get it now, thank you!
- BerislavLopac 2y ago> I have to use my meat brain to figure out if I've handled all the exceptions that might come up The point of exceptions is exactly that you don't want to handle all that might come up -- you need to handle only those that you actually expect and know how to handle. Everything else is left to bubble up and either be handled by a custom, generic top-level handler, or by the language's default mechanism (in Python's case, dumping a stack trace).