Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'handler': 0.05; 'classes.': 0.09; 'clause': 0.09; 'except:': 0.09; 'lawrence': 0.09; 'try:': 0.09; 'unhandled': 0.09; 'python': 0.11; 'exiting': 0.16; 'imo,': 0.16; 'old-style': 0.16; 'sys.exit(1)': 0.16; 'systemexit': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'normally': 0.19; 'not,': 0.20; 'example': 0.22; 'case.': 0.24; 'replace': 0.24; 'specify': 0.24; 'sort': 0.25; 'logging': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'usually': 0.31; 'equivalent.': 0.31; 'exceptions': 0.31; 'class': 0.32; 'fri,': 0.33; 'advice': 0.35; 'anywhere': 0.35; 'except': 0.35; 'case,': 0.35; 'received:google.com': 0.35; 'useful': 0.36; 'should': 0.36; 'depends': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'to:addr:python.org': 0.39; 'catch': 0.60; 'most': 0.60; 'such': 0.63; 'due': 0.66; 'believe': 0.68; '20,': 0.68; 'bare': 0.84; 'subject:check': 0.84; 'edwards': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=/WeDydOpqi8xtePKvT7Mx4+ZyfMv0mafg8mpxxfkkYk=; b=GaGqjur38nNEmmgY+YriAqQj6GRZfz7fuaheMHeUuvTFI8QNdFcQPztr433Tjebxjk HvhB6uv982LTMsN5YCo6d1+otxUxYJ9PrJBESXkWJcf7kTxzEZe0z6HL9YCWXJ5IXe7U BHVfY/orxfvFarPLXD1z/Q44dc6awCVShKvWZHGHMmVaOE6I0CkOP1xbwF8eCiAIYPzc mxITPQZ2aOg+S5q+xrH99Z055IjoisSwqrppB0gzAXXMTz4jfNhUn9i1YrG3Dz8MJymE 4oGYYBAerOY24iM50h4aGZknw17brerO//4tMppppfCaNyhGIdjCtfYAj9P42NpM2rj3 dInQ== X-Received: by 10.236.200.8 with SMTP id y8mr1762984yhn.137.1403279127350; Fri, 20 Jun 2014 08:45:27 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <1496766103424961606.682559sturla.molden-gmail.com@news.gmane.org> From: Ian Kelly Date: Fri, 20 Jun 2014 09:44:47 -0600 Subject: Re: how to check if a value is a floating point or not To: Python Content-Type: text/plain; charset=UTF-8 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1403279135 news.xs4all.nl 2880 [2001:888:2000:d::a6]:56915 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73465 On Fri, Jun 20, 2014 at 8:28 AM, Grant Edwards wrote: > On 2014-06-20, Mark Lawrence wrote: > >> For the OP a very important rule of thumb is never use a bare except, so >> this is right out. >> >> try: >> doSomething() >> except: >> WTF() > > IMO, that sort of depends on WTF() does. One case where a bare except > is well used is when stdandard output/error are not going anywhere > useful and you want to log the exception and then terminate: > > try: > whatever() > except Exception as e: > syslog("foobar: terminating due to unhandled exception %s.\n" % e) > sys.exit(1) Logging unhandled exceptions and exiting is the job of sys.excepthook, so I would prefer to replace it with a custom exception handler in this case. Also, this isn't an example of a bare except, which is an except clause with no exception class specified. "except:" and "except Exception:" are not equivalent. In Python 3, I believe that "except:" and "except BaseException:" are equivalent. In Python 2 they are not, because exceptions are also allowed to be old-style classes. In any case, the advice against bare excepts stems from the fact that bare excepts will catch things that you usually should not try to catch, such as SystemExit and KeyboardInterrupt, and so you should normally specify "except Exception:" in the most general case.