Exceptions and Finally in python
>>> Input
def foo():
try:
print "I am in foo"
return
except:
raise
finally:
print "finally of foo"
def foo_exec():
try:
print "I am in foo_exec"
raise Exception("Exception in foo_exec")
except:
raise
finally:
print "finally of foo_exec"
foo()
foo_exec()
>>> Output
I am in foo
finally of foo
I am in foo_exec
finally of foo_exec
Traceback (most recent call last):
File "a.py", line 20, in <module>
foo_exec()
File "a.py", line 13, in foo_exec
raise Exception("Exception in foo_exec")
Exception: Exception in foo_exec
Comments