Thursday, 19 September 2013

Netbeans giving me an error message but it works as I want it

Netbeans giving me an error message but it works as I want it

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:
function 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"
}
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?

No comments:

Post a Comment