The analysis of C # code flow is limited, and as your example shows, there are cases where all paths are returned, but the compiler cannot detect it. Throwing an exception is an acceptable remedy in these circumstances.
I would not use the default return to fix this error. You work on the assumption that the line never gets on the advice of the compiler. Consider for a second that your analysis is incorrect, and execution may go to the end of the method. If you return the default value, you will not have any indication of a problem. The method will simply return bad data. Throwing an exception will make it very obvious that there is a problem.
However, in those cases, I prefer to simply rewrite the code so that the compiler can see that all the paths end. In general, I found that if the method is so complex that the compiler cannot follow it, then the guy who takes the code after me will not be able to execute it.
source share