How to handle error in this case? By Exceptions or boolean or something else
- by TP
I am trying to create a Response class in Java which has a method
void setResponse(String response);
Different response subclasses will have different requirements for the response. The string that is passed to the function is received from the user.
What is the correct way of handling a wrong response?
Should the function throw an exception like IllegalResponseException
Should the function be declared like
boolean setResponse(String response, String errorMsg)
and return false if the response is wrong and set the error message to the appropriate value