I'm sure this issue has been addressed in many best practice books, but still ... In most cases, I see examples of misuse of user exceptions, so I was wondering what would be a good situation to use them?
In particular, at the moment I am working on type checking for a compiler course. So I have a SymbolTable class that looks pretty much like a map. The key difference from your regular map is that each character has no more than one definition, so the put (String, Object) operation should fail if the key we are trying to insert is already in SymbolTable.
So, here's the question: whenever we try to insert a key, and that key already exists in SymbolTable, what should SymbolTable look like? If we have
boolean insert(String key, Object value);
which returns false if insert fails, or should we use the insert method, which has a return value of void and throws an exception when a duplicate value occurs?
Thank you in advance:)
source share