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


Groups > comp.lang.python > #88843

Re: try..except with empty exceptions

Date 2015-04-12 07:37 +1000
From Cameron Simpson <cs@zip.com.au>
Subject Re: try..except with empty exceptions
References <CAPTjJmpBUct=UXMLdSpBTL8uH56qsMc6AZxg5SC7D=zt7Tqsig@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.234.1428788263.12925.python-list@python.org> (permalink)

Show all headers | View raw


On 11Apr2015 21:21, Chris Angelico <rosuav@gmail.com> wrote:
>But I agree, it would be very nice if Python 3 could have abolished
>the truly confusing part of this, where "except:" catches everything.
>Forcing people to spell it "except BaseException:" would fix all of
>this. How hard is it to deprecate and then remove that, same as string
>exceptions were removed?

I guess I'll go over there to oppose it then.

Why? It makes it harder to write portable python 2/3 code and does not add any 
semantic advantage.

Unless there's a common root exception class in Python 2, which I believe there 
isn't, you can't catch all exceptions in python 2 without the "except:" syntax.  
Which means the _only_ way to have some code in both 2 and 3 that does it 
requires 2 codebases.

As one who tries to have his code run in both 2 (usually recent 2, like 
2.6/2.7) and 3, this change would cause a signification breakage for me without 
bringing any semantic benefits.

Without vigorous use of the time machine I don't see a fix here.

For the record, I would be ok (but not "for") never having had bare "except" if 
all exceptions had always had a common root.

Hmm. Can I catch "object"? Sounds awful, but might work.

Cheers,
Cameron Simpson <cs@zip.com.au>

EMACS: Escape Meta Alt Control Shift

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


Thread

Re: try..except with empty exceptions Cameron Simpson <cs@zip.com.au> - 2015-04-12 07:37 +1000
  Re: try..except with empty exceptions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-12 14:05 +1000

csiph-web