On Fri, 1 May 2020 10:21:22 -0300
André Roberge <andre.robe...@gmail.com> wrote:

> On Fri, May 1, 2020 at 10:15 AM Rhodri James <rho...@kynesim.co.uk> wrote:
> 
> > On 01/05/2020 07:48, Ram Rachum wrote:
> > > There are 2 reasons I want this:
> > >
> > > 1. When I'm writing a try..except clause, I want to catch a specific
> > > exception like MissingArgumentsError rather than ValueError or TypeError.
> > > They're too ubiquitous. I don't want some other unexpected failure
> > > producing the same ValueError and triggering my except clause.
> >
> > If you want to catch MissingArgumentsError, you're doing something
> > really weird.  I'm trying to think of a realistic example and failing.
> >
> 
> This type of error is already caught and identified by Python as a
> TypeError in at least two different situations with the following (generic)
> error messages:
> 
> X takes Y positional arguments but Z was given
> 
> X missing 2 required positional arguments: Y and Z
> 
> 
> The fact that two such messages exist is indicative that this type of
> error do occur in realistic code.

"Realistic code"?  Those are both effectively syntax (i.e., compile
time) errors, and should be caught way before any code hits the street.
I agree with Rhodri:  if you're catching these errors at runtime, then
you're doing something really weird.  (And I agree with others:  if
you're catching these errors in a REPL or in unit tests, then you're
going to have to think about how to fix the problem regardless of the
label of the exception.)

(Well, if I use my imagination:  someone else is in control of your
environment, and they pulled in a new version of some library that
doesn't care about backwards compatility, and suddenly the runtime
behavior of your otherwise tested and debugged code is now failing.  But
that hardly seems like a common scenario.)

(Or maybe you're trying to build a genetic code generator and/or
debugger, and it's easier on your software to "guide" the evolution if
more information is encoded in the type of the exception rather than in
a human readable message.  But that also seems rather unlikely.)

Dan

-- 
“Atoms are not things.” – Werner Heisenberg
Dan Sommers, http://www.tombstonezero.net/dan
_______________________________________________
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/3AVTHZGUXVIVSDTNUV7TZ2WVU5CHRQ5Z/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to