Moved a line outside of try/except to prevent an error in finally.

Thanks Ian Foote.