[Python-ideas] Python-ideas Digest, Vol 93, Issue 31
Juancarlo Añez
apalala at gmail.com
Thu Aug 14 12:27:20 CEST 2014
On Thu, Aug 14, 2014 at 4:38 AM, Christian Heimes <christian at python.org>
wrote:
> I made the same suggestion a couple of hours earlier. A standardized and
> introspectable way to add exception annotation is a common request. It's
> especially useful for C code because it's very hard to impossible to
> deduce exceptions from C code.
>
> For now there is no need for a new syntax. IMHO a decorator and standard
> location for exception annotations are sufficient. Perhaps somebody is
> able to come up with a syntax later.
>
The problem with declaring raisable exceptions is that it invites static
verification of callers doing "the right thing" with them, as in Java, and
that introduces noise in the software development process that is almost
impossible to clean up.
@raises(ValueError)
def index(self, value):
pass
def found(self, value):
return self.index(value) >= 0
Is found() correct? If not, I assure you the most common (and probably
incorrect) solution will be:
def found(self, value):
try:
return self.index(value) >= 0
except ValueError:
return False
Or worse:
def found(self, value):
try:
return self.index(value) >= 0
except:
return False
The right thing to do with an exception is to let it through, unless you
know exactly what you have to do about it.
In this interview, Anders Hejlsberg talks about why checked exceptions were
left out of the design of C#:
http://www.artima.com/intv/handcuffs.html
Cheers,
--
Juancarlo *Añez*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140814/ea9d6d16/attachment.html>
More information about the Python-ideas
mailing list