Imagine that I have a main class that handles an HashMap of another type of class that I want to store in files using the interface serializable.
We can call the main class the Manager and the classes I want to save in files can be called Data.
Now, the Manager class has a method to save an instance of the Data class into a file (all instances of Data are stored in a HashMap in the Manager class). The name of the instance is entered my the user so it may not exists.
What should I do in cases like this? Check if the instance exists and if not I return false or make a function that returns void and throws an exception if the instance does not exists? Should I use exceptions in cases like this? Will exceptions make a big impact in the performance of a program (since every time we throw one we have to create a new object...)?
Thanks.