How to handle error in this case? By Exceptions or boolean or something else
Posted
by TP
on Stack Overflow
See other posts from Stack Overflow
or by TP
Published on 2010-04-25T08:07:29Z
Indexed on
2010/04/25
8:13 UTC
Read the original article
Hit count: 163
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
© Stack Overflow or respective owner