Should I generate the exception message (in my example from the linkparameter) or should my constructor take a message parameter?
class ReadFromNotConnectedInputException extends RuntimeException {
private String link;
public ReadFromNotConnectedInputException(final String link)
{
this.link = link;
}
public String getLink()
{
return link
}
public String getMessage()
{
return String.format("Cannot read from link \"%\", link not connected.", link);
}
}
Since you have opted for a
RuntimeException, this would imply that you do not intend to handle it locally (close to where it was thrown), but at some higher level in the stack, where you handle many different exceptions.In that context there will be no exception-specific logic involved; you’ll write an error entry to the log file and clean up. Therefore a simple
messageproperty would fit the bill better than a separate String property + a complexgetMessageimplementation.