Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'win32': 0.03; 'exception': 0.03; 'try:': 0.07; 'python': 0.09; 'lawrence': 0.09; 'nameerror:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sep': 0.09; 'terry': 0.09; 'url:peps': 0.09; "wouldn't": 0.11; '2.7.3': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:exception': 0.16; 'wrote:': 0.17; 'url:dev': 0.17; '>>>': 0.18; 'bit': 0.21; '"",': 0.22; 'keyboard': 0.22; 'defined': 0.22; 'idea': 0.24; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; '(most': 0.27; 'am,': 0.27; 'instead.': 0.27; 'header:X-Complaints-To:1': 0.28; 'skip:( 20': 0.28; 'catching': 0.29; 'probably': 0.29; "skip:' 10": 0.30; 'normally': 0.30; 'point': 0.31; 'url:python': 0.32; 'file': 0.32; 'from:addr:yahoo.co.uk': 0.32; 'not.': 0.32; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'done': 0.34; 'doing': 0.35; 'there': 0.35; 'received:org': 0.36; 'except': 0.36; 'but': 0.36; 'url:org': 0.36; "i'll": 0.36; 'subject:with': 0.36; 'should': 0.36; 'bad': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'some': 0.38; 'things': 0.38; 'advice': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; "you've": 0.61; 'more': 0.63; 'everything,': 0.84; 'interrupt': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Understanding and dealing with an exception Date: Sun, 14 Oct 2012 12:17:29 +0100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-146-1-240.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:16.0) Gecko/20121005 Thunderbird/16.0 In-Reply-To: X-Antivirus: avast! (VPS 121013-1, 13/10/2012), Outbound message X-Antivirus-Status: Clean 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: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350213448 news.xs4all.nl 6900 [2001:888:2000:d::a6]:60378 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31248 On 14/10/2012 11:06, Terry Reedy wrote: > On 10/14/2012 4:20 AM, Mark Lawrence wrote: > >> You've already had some advice so I'll just point out that a bare except >> is a bad idea as you wouldn't even be able to catch a user interrupt. >> Try (groan!) catching StandardError instead. > > There are some bare except:s in the stdlib, that adding another is > frowned on and removing one is smiled upon. > > However: > >>> StandardError > Traceback (most recent call last): > File "", line 1, in > StandardError > NameError: name 'StandardError' is not defined > > Try: > >>> Exception > > > This catches everything except a few things like Keyboard Interrupt that > you normally should not catch. > > >>> BaseException > > > This catches everything, but signals that doing so is probably intentional. > White Man type with forked fingers? c:\Users\Mark\Cash\Python>python Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> StandardError Perhaps not. c:\Users\Mark\Cash\Python>py -3 Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> StandardError Traceback (most recent call last): File "", line 1, in NameError: name 'StandardError' is not defined Down to this http://www.python.org/dev/peps/pep-3151/ or was it done earlier? -- Cheers. Mark Lawrence.