Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'sorts': 0.04; 'exception,': 0.07; 'python': 0.08; 'correct.': 0.09; 'exception.': 0.09; 'exceptions': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:gator410.hostgator.com': 0.09; 'throw': 0.09; '~ethan~': 0.09; 'subject:error': 0.10; 'received:gateway13.websitewelcome.com': 0.16; 'surprising': 0.16; 'unhandled': 0.16; 'wrote:': 0.16; '>>>': 0.18; '(which': 0.19; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'somehow': 0.23; 'libraries': 0.24; 'writes:': 0.25; "i'm": 0.27; 'host': 0.27; 'paul': 0.28; 'remote': 0.28; 'raise': 0.28; 'bugs': 0.28; 'mode': 0.28; 'operations': 0.30; 'bare': 0.30; 'down,': 0.30; 'fails,': 0.30; '(e.g.': 0.31; 'error': 0.32; 'list': 0.32; "what's": 0.33; 'to:addr:python-list': 0.33; 'header:User-Agent:1': 0.34; 'approach.': 0.34; 'record': 0.35; 'certain': 0.35; 'unless': 0.36; 'connection': 0.36; 'instead.': 0.37; 'but': 0.37; 'steven': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'etc.)': 0.39; 'represent': 0.39; 'either': 0.39; 'subject:with': 0.39; "there's": 0.39; 'data': 0.39; 'to:addr:python.org': 0.39; 'case': 0.39; "it's": 0.40; 'minimum': 0.40; 'received:websitewelcome.com': 0.64; 'ever': 0.65; 'received:184': 0.67; 'dealing': 0.69; 'failure': 0.73; 'everything.': 0.84; 'irrelevant.': 0.84; 'mention.': 0.84; 'pain': 0.84; 'remedy': 0.84; 'subject:... ': 0.84; 'subject:types': 0.84; 'absolutely': 0.98 Date: Sun, 21 Aug 2011 12:22:47 -0700 From: Ethan Furman User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: python-list@python.org Subject: Re: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> In-Reply-To: <7xty9ahb84.fsf@ruckus.brouhaha.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: c-67-170-168-84.hsd1.or.comcast.net ([192.168.74.5]) [67.170.168.84]:3545 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 2 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 1313954630 news.xs4all.nl 23973 [2001:888:2000:d::a6]:37806 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11956 Paul Rubin wrote: > Steven D'Aprano writes: >>> But there's no way to know what that minimum is. Python libraries throw >>> all sorts of exceptions that their documentation doesn't mention. >> Yes, you're absolutely correct. But it's also irrelevant. Most of those >> exceptions should not be caught, even if you know what they are, because >> they represent either bugs that should be fixed, or bad data which should >> raise an exception. A bare except, or except Exception, is hardly ever the >> right approach. > > I'm not sure what to do instead. The exceptions I'm currently dealing > with happen when certain network operations go wrong (e.g. network or > remote host is down, connection fails, etc.) The remedy in each case is > to catch the exception, log the error, and try the operation again > later. But there's no guaranteed-to-be-complete list in the Python docs > of all the exceptions that can be thrown. A new and surprising mode of > network failure can lead to an unhandled exception, unless you catch > everything. In a case like this I can see catching everything so long as (which you say you are doing) you log the error somehow -- what's really frustrating is when the error is simply tossed with no record whatsoever... what a pain to debug! ~Ethan~