It seems that despite setting it in the 'except BaseException' block,
it is still occasionally undefined in the 'finally' block when
triggered by a SystemExit exception.
This should hopefully prevent UnboundLocalError from
being raised from the 'finally' block from now on
Resolves T4236.