<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ancestor(self, index):
 """ Return the ``index``-th ancestor. The 0-th ancestor is the node itself, the 1-th ancestor is its parent node, etc. :param int index: the number of levels to go up :rtype: :class:`~aeneas.tree.Tree` :raises: TypeError if ``index`` is not an int :raises: ValueError if ``index`` is negative """

        if not isinstance(index, int):
            self.log_exc(u"index is not an integer", None, True, TypeError)
        if index < 0:
            self.log_exc(u"index cannot be negative", None, True, ValueError)
        parent_node = self
        for i in range(index):
            if parent_node is None:
                break
            parent_node = parent_node.parent
        return parent_node