Wouldn't it be safer to place this in a finally: block wrapped around the entire method's contents, and eliminate the extra calls in the error cases? I know, extra indentation for everything, but that will go away...