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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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(gvC ustomers);
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.AddWithValu e(Param.Ke y.ToString (), Param.Value.ToString());
}
da = new SqlDataAdapter(cmd);
cmd.CommandType = CommandType.StoredProcedur e;
ds = new DataSet();
da.Fill(ds);
closeCon();
}
catch (SqlException sqlex)
{
throw new Exception(ex.message);
}
return ds;
}
well say in the UIL I call an object in the UIL
BLL customers = new BLL();
customers.GetCustomers(gvC
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.AddWithValu
}
da = new SqlDataAdapter(cmd);
cmd.CommandType = CommandType.StoredProcedur
ds = new DataSet();
da.Fill(ds);
closeCon();
}
catch (SqlException sqlex)
{
throw new Exception(ex.message);
}
return ds;
}