I have a subclass which contains a function which returns a float. I call that function in a try catch statement, if the an if statement fails and the else catches it I want that function to "crash" by returning noting like this return;
Here is that function:
float calc(... some arguments ...) {
...
if (operator.equals("+")) number = num1+num2;
else if (operator.equals("-")) number = num1-num2;
else if (operator.equals("*")) number = num1*num2;
else if (operator.equals("/")) number = num1/num2;
else return; // Here Netbeans gives me an error saying "Missing return value"
return number;
}
Now this function is getting called in a try and I if the else gets executed I want the function to "crash" and go to the catch statement and give the user an error message. This works exactly the way I want it but why does Netbeans give me an error?? Is there another way to do this?