0

I was wondering why Python 3.3 kills the exception because of return in try/finally statement, take a look at this code:

import sys

def action1(): 
    try:
        action2() 
    finally: 
        return       # try/finally doesn't kill exceptions
                     # But with return, exceptions not propagated
def action2():
    raise Exception()

try:
    action1()

except Exception as e:   
    print("except clause")

Is this behavior desirable and where can we apply its usage?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
GIZ
  • 4,409
  • 1
  • 24
  • 43
  • This feature is not unique to python, and exists in Java too – Eric Apr 03 '17 at 19:21
  • Also the most recent version of 3.3 is two and a half years old, it's probably time to upgrade. – jonrsharpe Apr 03 '17 at 19:23
  • second half of this question doesn't feel like a duplicate to me – Eric Apr 03 '17 at 19:24
  • @Eric added [return eats exception](http://stackoverflow.com/q/517060/674039) which has a discussion about that part. – wim Apr 03 '17 at 19:29
  • Ok, Part of my question was answered by looking at other questions. But, the other part is still unclear. Is this behavior desirable and where can we apply its usage? – GIZ Apr 03 '17 at 20:21

0 Answers0