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
3 Answers
You can create your own exception for it.
Just create a new class DuplicateItemException, and make sure it extends Exception:
public static class DuplicateException extends Exception {
private static final long serialVersionUID = 6188088059604835525L; //change the number, if needed - was auto generated by eclipse
}
If you want to use an existing class - maybe IllegalArgumentException might fit, though not perfectly.
Comments
Why not create your own?
public class DuplicateItemException extends Exception
{
}
1 Comment
FranXh
I do not know how to create a class for an exception