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


Groups > comp.lang.python > #88844 > unrolled thread

Re: try..except with empty exceptions

Started byChris Angelico <rosuav@gmail.com>
First post2015-04-12 07:52 +1000
Last post2015-04-12 07:52 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: try..except with empty exceptions Chris Angelico <rosuav@gmail.com> - 2015-04-12 07:52 +1000

#88844 — Re: try..except with empty exceptions

FromChris Angelico <rosuav@gmail.com>
Date2015-04-12 07:52 +1000
SubjectRe: try..except with empty exceptions
Message-ID<mailman.235.1428789174.12925.python-list@python.org>
On Sun, Apr 12, 2015 at 7:37 AM, Cameron Simpson <cs@zip.com.au> wrote:
> 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.

Can you give an example of a place where in Py2 you absolutely have to
catch everything, and don't have control over the code, *and* are
trying to do a one-codebase routine with Py3 compatibility? If you're
trying for 2/3 compatibility, you'll need to have all your exceptions
derive from BaseException anyway.

At very worst, it could be turned into a compat-only syntax feature,
like the u"spam" noise prefix on Unicode strings - serving absolutely
no purpose in Py3 code, and ideally, able to be removed at some point
post-2020.

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web