On Fri, Sep 25, 2020 at 7:46 PM Sergio Fenoll <ser...@fenoll.be> wrote: > I'm really failing to see what part of my logic is faulty. I know that > any exception that isn't handled can be raised. I know that is the > expected behaviour. I don't expect every function to exhaustively > document every single exception it may raise (because as you and others > have said, that would include things like MemoryErrors and > KeyboardInterrupts). All I'm saying is that *some* exceptions are > "expected" by whomever implemented the function. To bring it back to my > earlier example, requests.get() raises a ConnectionError if it can't > connect to the url you pass it. It would be super useful as a caller of > that function to have this information *inside your IDE*. > > I really don't understand why it's faulty logic to want to have at least > *some* information about the exceptions a function *may* raise.
But requests.get() doesn't have a single raise statement anywhere in it. And if you dig through the entire source code for the requests package, you'll still only find a small number of the exceptions that might be raised. Errors come from anywhere, and if you're not handling them, you will simply let them bubble; is it your responsibility to document that? No. It's just the normal thing to do. When you want to catch an exception, don't look at the function to see what it's documented as raising. Look at its behaviour and see what it does that you can cope with. You're looking at things backwards and that's why you're wanting a list of possible things to catch. Instead, look at your program WITHOUT any exception handling, and see what exceptions are happening. Those are the ones to look at. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/2IN57NIPEGYLA4VBR5ODATC746BZMVBN/ Code of Conduct: http://python.org/psf/codeofconduct/