Posted by : Deepak Vasudevan Wednesday, October 08, 2008

'Not all codepaths return a value' -- Good Catch Error of C# Compiler

In most programming languages particularly when writing functions that involve complex conditions to evaluate and iterations to process, it is really a nightmare when we need to exit from the function from more than one place. Unless the function has a return type of void, it is going to be a pain for the caller of the function since if the exit in the callee is not accompanied by a proper return value, there is going to be an undefined (aka) NULL for the caller which it needs to handle.

I just wanted to share that in C#, the compiler catches this potential issue and flags it as an error 'Not all codepaths return a value'. Now you know and you can be sure to visit and review all exits from the function and ensure that the return is accompanied by a proper value to the return variable.

Popular Post

Blogger templates

Labels

Blog Archive

Followers

Blog Archive

Powered by Blogger.

- Copyright © Lavanya Deepak -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -