Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What does it referring to as error on custom method(not all code paths return a value)
Posted
Updated 15-Oct-11 8:05am
v2
Comments
theanil 15-Oct-11 14:13pm    
elobrate your question.

If the return value of a method isn't void, the method has to return a value or throw an exception.
Check that the whole of the paths in the method ends with return statement (or an exception) or put a return statement at the end of the method.
 
Share this answer
 
v2
Comments
Simon Bang Terkildsen 15-Oct-11 14:17pm    
Another good answer
Shmuel Zang 16-Oct-11 17:31pm    
Thanks.
Sergey Alexandrovich Kryukov 16-Oct-11 1:37am    
This is better answer because exception is mentioned -- important. My 5.
--SA
Shmuel Zang 16-Oct-11 17:29pm    
Thanks.
RaviRanjanKr 16-Oct-11 16:53pm    
Correct, My 5+
Method which return values and are not defined with void must return values in every case or as the compiler complains every execution branch.

Most likely you have a if statement and after it you have not written a return or you have a try catch and you have not defined the return after the catch etc.
 
Share this answer
 
Comments
Simon Bang Terkildsen 15-Oct-11 14:16pm    
Good answer, my 5.
Mehdi Gholam 16-Oct-11 1:02am    
Thanks
Sergey Alexandrovich Kryukov 16-Oct-11 1:37am    
True, my 5, but mentioning exception would be important, see the answer by Shmuel.
--SA

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