def raise_key_error_for_invalid_unicode(unicode_digit):
    """Unicode values should not be in the range D800 through DFFF because
    that is used for surrogate pairs in UTF-16

    :raises KeyError if unicode digit is invalid
    """
    if 55295 < unicode_digit < 57344:
        raise KeyError(
            'Unicode digit %d is invalid because it is in the range D800 through DFFF'
             % unicode_digit)
