exception alternative, returning object

Hi

In the function below, I need to handle the case if the singleLinkList is empty.
One option will be throw exception. But if I have made not to use exception here, what will be alternate way to handle such situation.

Thanks

1
2
3
4
5
6
7
8
9
10
11
template<typename T>
Node<T>& SingleLinkList<T>::InsertAfter(const Node<T>& node, const T& data) {
	if(this->IsNodeValid()) {
		Node<T>* newNode = new Node<T>(data);
		newNode->SetNext(node.GetNext());
		node.SetNext(newNode);
		return newNode;
	}
	else {
	}
}
Last edited on
I can't see the function returning a value. Should it?
Sorry, I had copied wrong function. I have corrected it.
How can a node be invalid and why would someone pass such a node to the function?
In that function there is constraint that the node should not be null and must be a member of list.
Topic archived. No new replies allowed.