Consider the following code:
try:
raise Exception("a")
except:
try:
raise Exception("b")
finally:
raise
This will raise Exception: a. I expected it to raise Exception: b (need I explain why?). Why does the final raise raise the original exception rather than (what I thought) was the last exception raised?
On python2.6
I guess, you are expecting the finally block to be tied with the “try” block where you raise the exception “B”. The finally block is attached to the first “try” block.
If you added an except block in the inner try block, then the finally block will raise exception B.
Output:
Another variation that explains whats happening here
Output:
If you see here, replacing the finally block with except does raise the exception B.