Help with Exception Handling in ASP.NET C# Application

Posted by Shrewd Demon on Stack Overflow See other posts from Stack Overflow or by Shrewd Demon
Published on 2010-05-11T06:50:56Z Indexed on 2010/05/11 6:54 UTC
Read the original article Hit count: 377

Filed under:
|
|

hi,

yesterday i posted a question regarding the Exception Handling technique, but i did'nt quite get a precise answer, partly because my question must not have been precise. So i will ask it more precisely.

There is a method in my BLL for authenticating user. If a user is authenticated it returns me the instance of the User class which i store in the session object for further references. the method looks something like this...

public static UsersEnt LoadUserInfo(string email)
{
    SqlDataReader reader = null;
    UsersEnt user = null;

    using (ConnectionManager cm = new ConnectionManager())
    {
        SqlParameter[] parameters = new SqlParameter[1];

        parameters[0] = new SqlParameter("@Email", email);

        try
        {
            reader = SQLHelper.ExecuteReader(cm.Connection,
                    "sp_LoadUserInfo", parameters);
        }
        catch (SqlException ex)
        {
            //this gives me a error object
        }

        if (reader.Read())
            user = new UsersDF(reader);
    }

    return user;
}

now my problem is suppose if the SP does not exist, then it will throw me an error or any other SQLException for that matter. Since this method is being called from my aspx.cs page i want to return some meaning full message as to what could have gone wrong so that the user understands that there was some problem and that he/she should retry logging-in again.

but i can't because the method returns an instance of the User class, so how can i return a message instead ??

i hope i made it clear !

thank you.

© Stack Overflow or respective owner

Related posts about exception-handling

Related posts about ASP.NET