25
A proposal for java's "throws" in python: Extend type hints to cover exceptions
(discuss.python.org)
Welcome to the Python community on the programming.dev Lemmy instance!
Past
November 2023
October 2023
July 2023
August 2023
September 2023
When I used to write Java and switched to Python, this was one of the things I missed. It was always quite clear which exceptions I had to catch (or not). Just today, I ran into the issue of trying to cover the exceptions a library could throw without using
except:
orexcept Exception as e
, but finally gave up and gave in to it. The linter wasn't happy, but fuck it.Lol. You're literally the only one that likes checked exceptions. And, it seems you think that it actually gives you information about what exceptions to catch. It does not. Most things just catch and rethrow as a RuntimException
Hey, I like checked exceptions too! I honestly think it's one of Javas's best features but it's hindered by the fact that try-catch is so verbose, libraries aren't always sensible about what exceptions they throw, and methods aren't exception-polymorphic for stuff like the Stream API. Which is to say, checked exceptions are a pain but that's the fault of the rest of the language around them and not the checked exceptions per se.