Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #112348

Re: Python Error message

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Terry Reedy <tjreedy@udel.edu>
Newsgroups comp.lang.python
Subject Re: Python Error message
Date Thu, 4 Aug 2016 15:36:38 -0400
Lines 35
Message-ID <mailman.176.1470339425.6033.python-list@python.org> (permalink)
References <710599b6-b8c3-4f5a-a3dd-48757b816a44@googlegroups.com> <57a36593$0$1590$c3e8da3$5496439d@news.astraweb.com> <CA+FnnTw3b-iudGYJomeUYRQo_4ZathC7E1vWVqLDGqDo74JfDA@mail.gmail.com> <23e36680-195e-b840-599e-e225cdc2cee8@mrabarnett.plus.com> <no05g6$b25$1@blaine.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de UORuWhdFdDyzEr6GBC4o2gBVGKWepf8iJmfjji+AERyg==
Return-Path <python-python-list@m.gmane.org>
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; 'subject:Python': 0.05; '(except': 0.05; 'mrab': 0.05; 'except:': 0.07; 'interpreted': 0.07; 'subject:Error': 0.07; 'executes': 0.09; 'handling,': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'statements': 0.09; 'throws': 0.09; 'whichever': 0.09; 'wrong,': 0.09; 'python': 0.10; 'jan': 0.11; 'exception': 0.13; 'file,': 0.15; 'interpreter': 0.15; 'handling.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'worst': 0.16; 'wrote:': 0.16; 'example.': 0.18; 'try:': 0.18; 'do.': 0.22; 'exceptions': 0.22; 'explicit': 0.22; 'latter': 0.22; 'code.': 0.23; 'errors': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'actual': 0.28; '(it': 0.29; 'raise': 0.29; 'code': 0.30; 'writes': 0.30; 'possibly': 0.32; 'idle': 0.33; 'raised': 0.33; 'rule': 0.33; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'needed': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'wrong': 0.38; 'log': 0.38; 'to:addr:python.org': 0.40; 'rare': 0.66; 'isolate': 0.84; 'of*': 0.84
X-Injected-Via-Gmane http://gmane.org/
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0
In-Reply-To <23e36680-195e-b840-599e-e225cdc2cee8@mrabarnett.plus.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <no05g6$b25$1@blaine.gmane.org>
X-Mailman-Original-References <710599b6-b8c3-4f5a-a3dd-48757b816a44@googlegroups.com> <57a36593$0$1590$c3e8da3$5496439d@news.astraweb.com> <CA+FnnTw3b-iudGYJomeUYRQo_4ZathC7E1vWVqLDGqDo74JfDA@mail.gmail.com> <23e36680-195e-b840-599e-e225cdc2cee8@mrabarnett.plus.com>
Xref csiph.com comp.lang.python:112348

Show key headers only | View raw


On 8/4/2016 12:19 PM, MRAB wrote:

> In those rare occasions when you do write a bare except,

A bare "except:" is never needed and in my opinion, and that of others, 
one should never write one (except possibly for experimentation). Be 
explicit and write "except BaseException:" or "except Exception:", 
whichever one is the actual intent.

 > you'd re-raise the exception afterwards:

As a general rule, this is wrong, just as this rule is wrong for other 
exception blocks.

> try:
>     ...
> except:
>     print("'tis but a scratch!")
>     raise

This is right when one wants to do something *in addition to* the normal 
handling, such as log errors to a file, but is wrong when wants to do 
something *instead of* allowing the normal handling.

An example of the latter is when one writes code in Python to execute 
'other' code.  (IDLE is one example.  It both executes user statements 
and evals user expressions.)  One needs "except BaseException:"  to 
isolate the interpreter from exceptions raised in the interpreted code. 
(It would be wrong for IDLE to stop because a user submitted code that 
raises, whether intentionally or accidentally)  A 'raise' that throws 
the exception into the interpreter is likely the worst thing to do.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python Error message GBANE FETIGUE <bemen77@gmail.com> - 2016-08-04 08:31 -0700
  Re: Python Error message Chris Angelico <rosuav@gmail.com> - 2016-08-05 01:51 +1000
  Re: Python Error message Steven D'Aprano <steve+python@pearwood.info> - 2016-08-05 01:56 +1000
    Re: Python Error message Igor Korot <ikorot01@gmail.com> - 2016-08-04 12:09 -0400
    Re: Python Error message Chris Angelico <rosuav@gmail.com> - 2016-08-05 02:14 +1000
    Re: Python Error message MRAB <python@mrabarnett.plus.com> - 2016-08-04 17:19 +0100
    Re: Python Error message Terry Reedy <tjreedy@udel.edu> - 2016-08-04 15:36 -0400
    Re: Python Error message Chris Angelico <rosuav@gmail.com> - 2016-08-05 05:53 +1000
  Re: Python Error message dieter <dieter@handshake.de> - 2016-08-05 09:03 +0200

csiph-web