Keep the KeyError check as close to the expected exception as possible.