Link to home
Start Free TrialLog in
Avatar of bschave2
bschave2

asked on

How to implement exception handling in a 3 tier web app

Hi,

I am new to the 3 tier development architecture and am looking to see what is the most common and efficient way to create error handling. Is it by creating a custom error handling object? Any help is much appreciated!
ASKER CERTIFIED SOLUTION
Avatar of Anil Golamari
Anil Golamari
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It depends entirely on what you need to do and what you need to report to the upper tiers. Trapping exceptions where they happen is usually best, and you will of course want to log them. You can then either re-throw the exception to, for example, let your UI know something went wrong. But whether you rethrow the original exception, or a more generic custom exception type is up to you.
Avatar of bschave2
bschave2

ASKER

How can I pass the exception back to the UIl?

well say in the UIL I call an object in the UIL

BLL customers = new BLL();
customers.GetCustomers(gvCustomers);

in the BLL method I get the gridview:

public void GetCustomers(GridView gvCustomers)
    {

        DLL getGV = new DLL();
        gvCustomers.DataSource = getGV.getDS("getCusts");
        gvCustomers.DataBind();
    }

And in the DLL i have the method as

public DataSet getDS(string ProcName, SortedList<string, string> sqlParams)
    {
        try
        {
            getCon();
            cmd = new SqlCommand(ProcName, con);

            //Looping through params.
            foreach (KeyValuePair<string, string> Param in sqlParams)
            {
                cmd.Parameters.AddWithValue(Param.Key.ToString(), Param.Value.ToString());

            }
            da = new SqlDataAdapter(cmd);
            cmd.CommandType = CommandType.StoredProcedure;
            ds = new DataSet();
            da.Fill(ds);

            closeCon();
        }
        catch (SqlException sqlex)
        {
            throw new Exception(ex.message);
        }

        return ds;
    }