| |

VerySource

 Forgot password?
 Register
Search
View: 702|Reply: 6

"HLLW.ClassBase.blnConnectAccess (string)": Not all code paths return a value

[Copy link]

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Great Britain

Post time: 2020-1-31 15:40:01
| Show all posts |Read mode
How do I resolve this error?
I want to customize a method in the newly created cs file, as follows:
bool blnConnectAccess (string strAccountPath)
        {
            if (strAccountPath! = "")
            {
                if (System.IO.File.Exists (strAccountPath))
                {

                }
                else
                {
                    
                }
            }
        }

The result is that prompt, somehow why? How to solve it?
Reply

Use magic Report

1

Threads

7

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-10 16:45:01
| Show all posts
bool blnConnectAccess (string strAccountPath)
        {
            bool somethingCool;
            if (strAccountPath! = "")
            {
                if (System.IO.File.Exists (strAccountPath))
                {

                }
                else
                {
                    
                }
            }
            return somethingCool;
        }
Reply

Use magic Report

0

Threads

52

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-3-10 17:00:01
| Show all posts
bool blnConnectAccess (string strAccountPath)
{
if (strAccountPath! = "")
{
if (System.IO.File.Exists (strAccountPath))
{
return true;
}
else
{
return false;
}
}
else return false;
}
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-11 20:45:01
| Show all posts
All exits of the function should be written with the return value
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-3-11 23:15:02
| Show all posts
TO: if (strAccountPath! = "")
            {
             }

The reason for your error is here:

strAccountPath! = "" You processed it, what if strAccountPath == ""? No return value ...

Add else return ..;

Or directly return ..
Reply

Use magic Report

2

Threads

29

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-3-12 15:30:01
| Show all posts
Not all code paths return a value
This shows that there may be no return value in your branch, and your return value is not void, you have to return something to him. From your code above, there is nothing
Reply

Use magic Report

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-17 20:15:01
| Show all posts
It ’s a good explanation, I know it at a glance, thanks!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list