Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'subject:Python': 0.05; 'paths': 0.05; 'received:134': 0.05; 'filename': 0.07; 'try:': 0.07; 'python': 0.09; 'e.errno': 0.09; 'errno': 0.09; 'ioerror': 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; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subclasses.': 0.16; 'wrote:': 0.17; 'import': 0.21; 'example': 0.23; 'raise': 0.24; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'found.': 0.27; 'header:X-Complaints-To:1': 0.28; "d'aprano": 0.29; 'steven': 0.29; 'file': 0.32; 'to:addr:python-list': 0.33; 'received:org': 0.36; 'except': 0.36; 'but': 0.36; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'here': 0.65; 'special': 0.73 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Serhiy Storchaka Subject: Re: Awsome Python - chained exceptions Date: Fri, 15 Feb 2013 20:51:21 +0200 References: <5119de00$0$11096$c3e8da3@news.astraweb.com> <1bc6cf63-9219-4798-ae01-dfe9643d96b4@googlegroups.com> <24e6e890-6f8a-43d1-a622-63bcb407f722@googlegroups.com> <511c8697$0$11096$c3e8da3@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 134.249.80.25 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 In-Reply-To: <511c8697$0$11096$c3e8da3@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360954301 news.xs4all.nl 6972 [2001:888:2000:d::a6]:34720 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38947 On 14.02.13 08:39, Steven D'Aprano wrote: > Here is one example of using raise to re-raise an exception you have just > caught: > > import errno > paths = ["here", "there", "somewhere else"] > for location in paths: > filename = os.path.join(location, "prefs.ini") > try: > f = open(filename) > except IOError as e: > if e.errno != errno.ENOENT: # File not found. > raise > In Python 3.3: try: f = open(filename) except FileNotFound: pass But not all errnos have special OSError subclasses.