Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Random832 Newsgroups: comp.lang.python Subject: Re: Handling exceptions with Py2 and Py3 Date: Fri, 27 May 2016 09:42:59 -0400 Lines: 12 Message-ID: References: <57483C86.6030304@gmail.com> <8537p3abbm.fsf@benfinney.id.au> <1464356579.642821.620565345.3949553F@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de YyS+B2oy6tn0h7mlEMLNWQ3e/Eo9juQwFgmV932TrG6w== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'errno': 0.09; 'oserror': 0.09; 'received:internal': 0.09; 'python': 0.10; 'ignore': 0.14; 'hierarchy': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:66.111.4.27': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:out3-smtp.messagingengine.com': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'try:': 0.18; 'second': 0.24; 'header:In- Reply-To:1': 0.24; 'error': 0.27; 'fri,': 0.27; 'types.': 0.29; 'class': 0.33; 'except': 0.34; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'received:66': 0.38; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'header :Message-Id:1': 0.61 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=D2AHN0GvfbV0hs6YujwS7IzQ8YI=; b=J73rzS 5P0PaJaG+nrsEFEHYJiiSWU30HuoRkM8paBwQRBjg/3TZZX1R7Is+gIp8kQYhxi1 BDnVlzlPtrWUBDbbVFO6ZLolv2m94zw98paIAFGo3A9TxlNLaARPy2Qhg/92x6T4 T4BJV5iTEIRId/0FHn9pbh5J93EllgJQpYGDI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=D2AHN0GvfbV0hs6 YujwS7IzQ8YI=; b=japZyy6Ktd2oiv+udL7JJtYMk7GFf534wcpDGOQpUsuGgOZ 7XXeuV9rxpxGd3oLfcFZkx6BnSJi+HeYlrn80z8NCC4iYQU40IvyPTyVbgo1b1Uu clXLJo2XJzbijTP4KpX7CG0vabgpVq6BvAPFqz35UTowfUXQMA9cWSCg4tuY= X-Sasl-Enc: 7wXSu8sI+iZy4GaJudO0Oo0lpwDkdvvI4GKvwxoCWyzR 1464356579 X-Mailer: MessagingEngine.com Webmail Interface - ajax-b882aaad In-Reply-To: <8537p3abbm.fsf@benfinney.id.au> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <1464356579.642821.620565345.3949553F@webmail.messagingengine.com> X-Mailman-Original-References: <57483C86.6030304@gmail.com> <8537p3abbm.fsf@benfinney.id.au> Xref: csiph.com comp.lang.python:109172 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.