<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def truncate(string, maxchar):
 """ Truncate a string to a maximum number of characters. If the string is longer than maxchar, then remove excess characters and append an ellipses. Arguments: string (str):
 String to truncate. maxchar (int):
 Maximum length of string in characters. Must be >= 4. Returns: str: Of length <= maxchar. Raises: TruncateError: In case of an error. """

    if maxchar < 4:
        raise TruncateError("Maxchar must be > 3")

    if len(string) <= maxchar:
        return string
    else:
        return string[:maxchar - 3] + "..."