O 25/09/20 ás 11:34, Chris Angelico escribiu:
On Fri, Sep 25, 2020 at 7:19 PM Sergio Fenoll <ser...@fenoll.be> wrote:
O 25/09/20 ás 10:56, Chris Angelico escribiu:

There's the shallow "exceptions that I expect to raise", which is
those explicitly listed within the function as raise statements; but
that's not the whole story, since exceptions can be raised by anything
that the function calls. So, no, I don't think the callee should have
a notion of "exceptions that I or anyone I call might raise".

ChrisA
I don't understand the need of talking about "exceptions that something
I call might raise" (from the POV of the callee) though, to me they are
irrelevant in this discussion. When you implement a function, you are
handling all/some/none exceptions and letting all/some/nonebubble up and
be handled by whatever called you, right? Somewhere, be it in a
docstring, some manual, external documentation, ... you write down what
exceptions you expect to raise, be it explicit or implicit (e.g. by
letting a known exception bubble up without explicitly raising it
yourself).
Look at your own code. Do you know what EVERY function you call could
raise? If not, then your code could raise those exceptions. It's not
about "letting a known exception bubble up". It's the *normal
behaviour* of letting all exceptions bubble up unless explicitly
caught. Don't think in terms of knowing every exception that could be
raised. That simply doesn't work, and it leads to faulty logic like
this.

ChrisA


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.
_______________________________________________
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/WIBFHB2MBQ2DFINRWCAL72TJJRXGAF52/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to