Hi everyone this is my first question so I apologies if this has been answered somewhere before but I couldn't find an answer to the question so I'm posting it here.
In the case where your method has a return value that can be positive or negative, and you are unsure of the range the return value, what value should you return if you get an exception?
For example in the method below-
public double calculateDifference(String studentName, String quizName) {
try {
Quiz quiz = quizDAO.retrieve(quizName);
double averageScore = quiz.getAverageScore();
Student student = quiz.getStudent(studentName);
double score = student.getScore();
return score - averageScore;
} catch (NullPointerException e) {
return -1;
}
}
Assuming score and average score have a large range, what if my return value in my catch is equal to the value returned when there is no exception?
For example, score=2, and average score=3, so I will get -1 as a return value.
When I get that return value I'm unsure of whether an exception was caught or not.
What I'm asking I guess is if there is a way, when caught, to return a unique double value that doesn't clash with other possible return values.