Returning a value on exception

asp.net, asp.net-2.0, exception

Solution

You forgot to put a return outside of the if, put it after the if ending brace

public bool isUserProfileHashed(string username)
{
    bool isHashed = false;
    MembershipUser u = null;
    u = Membership.GetUser(username);
    if (u != null)
    {
        try
        {
            u.GetPassword();                   
        }
        catch
        {
            // An exception is thrown when the GetPassword method is called for a user with a hashed password
            isHashed = true;
        }
    }
    return isHashed;
}

[Edit] Remove unnecessary return (@Fredrik Mörk) Caught exception not used hence removed it as well.

Problem

Why does this code not compile? It gives me the error: not all code paths return a value Code: ``` public bool isUserProfileHashed(string username) { bool isHashed = false; MembershipUser u = null; u = Membership.GetUser(username); if (u != null) { try { u.GetPassword(); } catch (Exception exception) { // An exception is thrown when the GetPassword method is called for a user with a hashed password isHashed = true; return isHashed; } return isHashed; } ```

Original source