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


Groups > comp.lang.python > #84872

Re: The Most Diabolical Python Antipattern

References (1 earlier) <20150129113238.7eaa986d@bigbox.christie.dr> <mailman.18286.1422571931.18130.python-list@python.org> <87r3uchjyg.fsf@elektro.pacujo.net> <mailman.18296.1422605482.18130.python-list@python.org> <87r3ucljyv.fsf@elektro.pacujo.net>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2015-01-30 02:17 -0700
Subject Re: The Most Diabolical Python Antipattern
Newsgroups comp.lang.python
Message-ID <mailman.18300.1422609481.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Jan 30, 2015 at 2:02 AM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Mark Lawrence <breamoreboy@yahoo.co.uk>:
>
>> On 30/01/2015 06:16, Marko Rauhamaa wrote:
>>> How about:
>>>
>>> ==============================
>>>      try:
>>>          do_interesting_stuff()
>>>      except ValueError:
>>>          try:
>>>              log_it()
>>>          except:
>>>              pass
>>>          raise
>>> ==============================
>>>
>>> Surprisingly this variant could raise an unexpected exception:
>>>
>>> ==============================
>>>      try:
>>>          do_interesting_stuff()
>>>      except ValueError:
>>>          try:
>>>              log_it()
>>>          finally:
>>>              raise
>>> ==============================
>>>
>>> A Python bug?
>>
>> It depends on the Python version that you're running - I think!!!  See
>> https://www.python.org/dev/peps/pep-3134/
>
> TL;DR
>
> My Python did do exception chaining, but the problem is the surface
> exception changes, which could throw off the whole error recovery.
>
> So I'm thinking I might have found a valid use case for the "diabolical
> antipattern."

I suppose, although it seems awfully contrived to me. In any case it
would still be better with "except Exception" rather than the bare
except. Unless re-raising that ValueError is more important to you
than letting the user hit Ctrl-C during the logging call.

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


Thread

Re: The Most Diabolical Python Antipattern Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-29 15:51 -0700
  Re: The Most Diabolical Python Antipattern Marko Rauhamaa <marko@pacujo.net> - 2015-01-30 08:16 +0200
    Re: The Most Diabolical Python Antipattern Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-30 08:10 +0000
      Re: The Most Diabolical Python Antipattern Marko Rauhamaa <marko@pacujo.net> - 2015-01-30 11:02 +0200
        Re: The Most Diabolical Python Antipattern Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-30 02:17 -0700
        Re: The Most Diabolical Python Antipattern Marko Rauhamaa <marko@pacujo.net> - 2015-01-30 12:00 +0200
          Re: The Most Diabolical Python Antipattern Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-30 08:21 -0700
            Re: The Most Diabolical Python Antipattern Marko Rauhamaa <marko@pacujo.net> - 2015-01-30 17:30 +0200
              Re: The Most Diabolical Python Antipattern Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-30 08:42 -0700
                Re: The Most Diabolical Python Antipattern Marko Rauhamaa <marko@pacujo.net> - 2015-01-30 17:56 +0200
                Re: The Most Diabolical Python Antipattern Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-30 09:38 -0700
              Re: The Most Diabolical Python Antipattern Chris Angelico <rosuav@gmail.com> - 2015-01-31 02:55 +1100
    Re: The Most Diabolical Python Antipattern Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-30 02:11 -0700
    Re: The Most Diabolical Python Antipattern Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-31 01:28 +0000

csiph-web