Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109174
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Ben Finney <ben+python@benfinney.id.au> |
| Newsgroups | comp.lang.python |
| Subject | Re: Handling exceptions with Py2 and Py3 |
| Date | Sat, 28 May 2016 00:04:10 +1000 |
| Lines | 27 |
| Message-ID | <mailman.23.1464357859.2277.python-list@python.org> (permalink) |
| References | <57483C86.6030304@gmail.com> <8537p3abbm.fsf@benfinney.id.au> <1464356579.642821.620565345.3949553F@webmail.messagingengine.com> <85wpmf8un9.fsf@benfinney.id.au> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | news.uni-berlin.de l23dC+H8VXDnf6S+1nMi9QhV4y3DgQqzcQfUkMUCzWoQ== |
| Cancel-Lock | sha1:FrnTMGevxmDajdyM8G5DSKzcnpg= |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'discard': 0.05; 'errno': 0.09; 'oserror': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; ':-)': 0.12; 'ignore': 0.14; 'aspire': 0.16; 'hierarchy': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'try:': 0.18; 'wrote': 0.23; 'second': 0.24; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.26; 'error': 0.27; 'fri,': 0.27; 'right.': 0.27; 'types.': 0.29; 'code': 0.30; 'older': 0.32; 'class': 0.33; 'legacy': 0.33; 'except': 0.34; 'but': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'day': 0.67; '_o__)': 0.84; 'desires': 0.84; 'emotion': 0.84; 'isolate': 0.84; 'received:125': 0.84; 'luxury': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | jigong.madmonks.org |
| X-Public-Key-ID | 0xAC128405 |
| X-Public-Key-Fingerprint | 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 |
| X-Public-Key-URL | http://www.benfinney.id.au/contact/bfinney-pubkey.asc |
| X-Post-From | Ben Finney <bignose+hates-spam@benfinney.id.au> |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <85wpmf8un9.fsf@benfinney.id.au> |
| X-Mailman-Original-References | <57483C86.6030304@gmail.com> <8537p3abbm.fsf@benfinney.id.au> <1464356579.642821.620565345.3949553F@webmail.messagingengine.com> |
| Xref | csiph.com comp.lang.python:109174 |
Show key headers only | View raw
Random832 <random832@fastmail.com> writes: > On Fri, May 27, 2016, at 09:18, Ben Finney wrote: > > try: > > short_routine() > > except ConnectionRefusedError as exc: > > handle_connection_refused(exc) > > except OSError as exc: > > if exc.errno == errno.ECONNREFUSED: > > handle_connection_refused(exc) > > But ConnectionRefusedError inherits from OSError and has errno = > ECONNREFUSED. So you can simply only have the second except block here, > and ignore the fact that Python 3 has a class hierarchy of error types. That's right. I wrote the above to isolate the older clumsy way, and make it easier to remove. Every Python 2-and-3 code base should aspire to one day discard the Python 2 legacy cruft :-) -- \ “For a sentimentalist is simply one who desires to have the | `\ luxury of an emotion without paying for it.” —Oscar Wilde, _De | _o__) Profundis_, 1897 | Ben Finney
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Handling exceptions with Py2 and Py3 Ben Finney <ben+python@benfinney.id.au> - 2016-05-28 00:04 +1000
csiph-web