I want to add an element to a BinarySearchTree. I have a condition that checks if the element is already in the tree and if it is I want to throw an exception. My problem is that I do not know what type, or what the name of this exception is. I was looking for DublicateItemException but it does not work. I am working with java. Any ideas? Thanks
Share
The Java
TreeSetsimply returnsfalsewhen you try to add an already-present element to the tree, butQueuesets an alternative precedent of throwing anIllegalStateException. There’s no exception built into Java for the case you’re looking for, though.