Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
"Not all code paths return a value". Please explain about this error.
Posted
Comments
RaisKazi 21-Dec-11 1:48am    
Post your code.
Al Moje 21-Dec-11 1:54am    
You made a function or method that expects to return an explicit value but you fail to do...

This kind of error generally occurs when you are branching out your code (using if-else or switch case) and then returning values from some of the conditions but not all.

This is the compiler error CS0101 and you can read more about it here[^]. They have a sample that should explain the error to you as well.
 
Share this answer
 
Comments
[no name] 21-Dec-11 1:52am    
My 5+
Abhinav S 21-Dec-11 1:56am    
Thanks.
koolprasad2003 21-Dec-11 1:53am    
Yes. abhinav. OP has not return value from function.
good suggestion.5.
Abhinav S 21-Dec-11 1:56am    
Thanks.
Simple. Error suggest you exact problem.
You have a function in which you may have not return any value or return value in if loop.
to resolve it check following things
1. change the function return to VOID (if you does not return something)
2. give return keyword with variable name before end function
 
Share this answer
 
Comments
Abhinav S 21-Dec-11 1:56am    
5! However, OP needs to add a return statement to cover the method rather than remove it completely.
maajanes 21-Dec-11 2:25am    
I have returned the respective value. Yet i am getting that error....
lukeer 21-Dec-11 2:53am    
Improve your question using the "Improve question" link. Post the method causing the error.

We're going to see at least one possible code path that does not return a value.
In your method if your method returning a value then, The error shows that there are still some possible ways missing for returning your data from method.

You can give me code portion where you find this kind of error. I will mark possible ways you left.
 
Share this answer
 
Comments
maajanes 21-Dec-11 4:42am    
THE CODE:

private bool isvalidationreq_groupq(DataView Subquestion)
{
try {
int i = 0;
thisSubQuestionserial = 1;
bool retval = false;
for (i = 0; i <= Subquestion.Count - 1; i++) {
if (Convert.ToInt32(Subquestion[i]["Validationcount"]) > 0) {
Validationtext.Add(Subquestion[i]["Question_ID"].ToString(), " for Question-" + thisQuestionserial.ToString() + "." + thisSubQuestionserial.ToString());
retval = true;
}
thisSubQuestionserial += 1;
}
thisSubQuestionserial = 1;
return retval;
}catch (Exception ex) {
Survey2_0.ReusableComponents.MyExceptionLogger.Publish(ex);
}

}
Quirkafleeg 21-Dec-11 6:11am    
Hint: What do you return after you've handled the exception?
lukeer 21-Dec-11 9:48am    
It looks a lot nicer if you use the "Improve question" link and place your code there within those tags: <pre lang="c#">YourCode</pre>.
That way we could look at it with those fancy code word colours we all love.
fasfasdf
 
Share this answer
 
Comments
CHill60 12-Jun-15 8:33am    
Don't be silly

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900