C# error “Not all code paths return a value”

后端 未结 8 1879
长发绾君心
长发绾君心 2020-12-12 06:05

I translated this part of the code from vb to c# and giving me this error message. \"Not all code paths return a value\". What is the problem? Thanks in advance.

<         


        
8条回答
  •  盖世英雄少女心
    2020-12-12 06:31

    This is because in the case of any exception occurs,the exception will thrown to the catch, in that case the code will not return any value. so you have to return some value from the catch to avoid this issue

    Replace the catch with this:

            catch
            {
                //error handling goes here
                UnhandledExceptionHandler();
                return new DataSet();
            }
    

提交回复
热议问题