Here is the Code :
def funcFail():
try:
raise Exception("Failed externally")
print("Should not print")
except Exception as e:
print(f"Exception : {e}")
raise Exception(f"Exception in occured due: {e}")
finally:
return "This is finally block :P"
print("This is finally block :P")
def checkexpcep():
global k
k = []
try:
funcFail()
except Exception as e:
print(f"Exception out : {e}")
k.append(str(e))
finally:
return "nothing"
checkexpcep()
Expected :
"Exception : Failed externally"
"This is finally block :P"
"Exception out : Exception in occured due: Failed externally"
Output :
"Exception : Failed externally"
If you actually want your expected output, then just move the
return
out of thefinally
block:Output:
(Note I added the print of a
tuple
at the end to show the value ofk
)