Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #109174

Re: Handling exceptions with Py2 and Py3

From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: Handling exceptions with Py2 and Py3
Date 2016-05-28 00:04 +1000
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>

Show all headers | 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


Thread

Re: Handling exceptions with Py2 and Py3 Ben Finney <ben+python@benfinney.id.au> - 2016-05-28 00:04 +1000

csiph-web