I think it is accepted that as a general rule in Java (and perhaps any language with exception handling) one should try to avoid using exception handling to actually handle business logic. In general, if it is expected that a certain situation is supposed to happen, one should check for it and handle it more directly than relying on exception handling to do the checking for you. For example, the following is not considered good practice:
try{
_map.put(myKey, myValue);
} catch(NullPointerException e){
_map = new HashMap<String, String>();
}
Instead lazy initialization should be accomplished more like this:
if(_map == null){
_map = new HashMap<String, String>();
}
_map.put(myKey, myValue);
Of course there could be far more complex logic than simply handling lazy initialization. So given that this type of thing is usually frowned upon...when, if ever, is it a good idea to rely on an exception happening for certain business logic to occur? Would it be accurate to say that any instance where one feels compelled to use this approach is really highlighting a weakness of the API being used?