Marko Rauhamaa <ma...@pacujo.net>:

>>> Surprisingly this variant could raise an unexpected exception:
>>>
>>> ==============================
>>>      try:
>>>          do_interesting_stuff()
>>>      except ValueError:
>>>          try:
>>>              log_it()
>>>          finally:
>>>              raise
>>> ==============================
>>>
>>> A Python bug?
> [...]
> My Python did do exception chaining, but the problem is the surface
> exception changes, which could throw off the whole error recovery.

BTW, the code above can be fixed:

==============================
  try:
      do_interesting_stuff()
  except ValueError as e:
      try:
          log_it()
      finally:
          raise e
==============================

Now the surface exception is kept and the subsidiary exception is
chained to it.

I'm a bit baffled why the two pieces of code are not equivalent.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to