Answer the question
In order to leave comments, you need to log in
How to throw a RuntimeException at the line "double weight = 1.0;"?
There is the following method:
public static double weight(Some input params) {
double weight = 0.0;
try {
weight = 1.0;
} catch(RuntimeException error) {
// some error handling logic here
weight = 0.0;
}
return weight;
}
Answer the question
In order to leave comments, you need to log in
I don't really understand what the problem is either. Set a forced throw new RuntimeException();, test the processing logic, and then remove the forced throwing of the exception.
Well, if you want to be absolutely “awesome and inflated”, then replace “weight = 1.0;” to “weight = _dataProvider.getWeightData()”, where in “normal” mode _dataProvider is an instance of the “correct” class (returning normal data), and in test mode it is an instance of a special test class that inherits the same interface, but instead of normal data throwing exceptions.
Just be careful with that, don't end up with " factory factory tool factory " :D
To be honest, it's not clear what the question is? What is the problem?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question