You can find the descriptions of all the default exceptions here: https://docs.python.org/3/library/exceptions.html
For instance,
TypeError
Raised when an operation or function is applied to an object of inappropriate type. The associated value is a string giving details about the type mismatch.
This exception may be raised by user code to indicate that an attempted operation on an object is not supported, and is not meant to be. If an object is meant to support a given operation but has not yet provided an implementation, NotImplementedError is the proper exception to raise.
Passing arguments of the wrong type (e.g. passing a list when an int is expected) should result in a TypeError, but passing arguments with the wrong value (e.g. a number outside expected boundaries) should result in a ValueError.
ValueError
Raised when an operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError.
However, sometimes, it makes sense to think about defining a custom Exception. In your case, it could be
class GraphError(Exception):
pass
raise GraphError("Node foo - rank limit exceeded")
or
class LinkError(Exception):
message = "Node {node} - rank limit exceeded"
def __init__(self, node):
super(LinkError, self).__init__(
self.message.format(
node=node,
)
)
self.node = node
raise LinkError('foo')