Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26371
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: NameError vs AttributeError |
| Date | 2012-08-01 12:59 -0400 |
| References | <u1pke9-a46.ln1@satorlaser.homedns.org> <jv9eo7$jit$1@dough.gmane.org> <CALvWhxv8ww08AW_+N7K=XLnqOAz6Bmtd80M8qAeb3r4RCCm-8Q@mail.gmail.com> <jv9sce$lgm$1@dough.gmane.org> <50195104.108@stoneleaf.us> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2839.1343840406.4697.python-list@python.org> (permalink) |
On 8/1/2012 11:53 AM, Ethan Furman wrote: > Terry Reedy wrote: >> On 7/31/2012 4:49 PM, Chris Kaynor wrote: >>> On Tue, Jul 31, 2012 at 1:21 PM, Terry Reedy wrote: >>>> one wants to catch both errors, one can easily enough. To continue >>>> the example above, popping an empty list and empty set produce >>>> IndexError and KeyError respectively: >>>> >>>> try: >>>> while True: >>>> process(pop()) >>>> except (KeyError, IndexError): >>>> pass # empty collection means we are done >>>> >>> There is a base type for KeyError and IndexError: LookupError. >>> >>> http://docs.python.org/library/exceptions.html#exception-hierarchy >> >> Oh, so there is. Added in 1.5 strictly as a never-directly-raised base >> class for the above pair, now also directly raised in codecs.lookup. I >> have not decided if I want to replace the tuple in the code in my book. > > I think I'd stick with the tuple -- LookupError could just as easily > encompass NameError and AttributeError. Thank you. Having to remember exactly which lookup error is encompassed by LookupError illustrates my point about the cost of adding entities without necessity. It also illustrates the importance of carefull naming. SubscriptError might have been better. -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
NameError vs AttributeError Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-07-31 12:36 +0200 Re: NameError vs AttributeError Terry Reedy <tjreedy@udel.edu> - 2012-07-31 16:21 -0400 Re: NameError vs AttributeError Terry Reedy <tjreedy@udel.edu> - 2012-07-31 20:14 -0400 Re: NameError vs AttributeError Ethan Furman <ethan@stoneleaf.us> - 2012-08-01 08:53 -0700 Re: NameError vs AttributeError Terry Reedy <tjreedy@udel.edu> - 2012-08-01 12:59 -0400
csiph-web