help needed on ObjectDataSource control

G

Guest

HI,

How to catch custom exception using ObjectDataSource Control.
I am calling Business Layer method through ObjectDataSource control, when
Business layer method throws exception which will be wrapped to custom
exception and thrown. I want to capture the custom exception in UI Layer.

e.g.,
UI Layer Code:
protected void Page_Load(object sender, EventArgs e)
{
try
{
ObjectDataSource1.SelectMethod = "GetAllRoles";

ObjectDataSource1.TypeName =
"Shell.BizTalk.Services.BizDashboard.BusinessLayer.RoleBL";
GridView1.DataSourceID = "ObjectDataSource1";
GridView1.DataBind();
}
catch (BizDashboardException objBizDashboardException) // want to capture Here
{
string s1 = objBizDashboardException.errorNo;
BizDashboardException.publish(objBizDashboardException);
}
catch (Exception ex)
{
string s = ex.InnerException.Message; // Always capture this exception
}


}

Business Layer Code:
public static roleData GetAllRoles()
{
roleData objRoleData = null;
try
{
int x = objRoleData.Tables[0].Rows.Count;
}

catch (Exception objException) // Converting to Custom Exception
{
throw new BizDashboardException("BSC-001", objException,
objException.Message, "RoleBL-GetAllRoles", Severity.Warning);
}
return objRoleData;
}
 
F

Flinky Wisty Pomm

Try handling the Selected event of your ObjectDataSource:

protected void ObjectData_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
BizDashboardException ex = e.Exception as BizDashboardException;
if (null != ex)
{
BizDashboardException.publish(ex);
e.ExceptionHandled = true;
}
}



Also, unless you have a _really_ good reason, don't ever do

try
{
...
}
catch(System.Exception ex)
{
DoAbsolutelyNothingWithException(ex);
}

or you won't find out that your app is broken until it's too late.
 
G

Guest

HI Flinky Wisty Pomm,

I tried the solution which u provided which is working fine, there is
small changes in the code as below

BizDashboardException ex = e.Exception.InnerException as
BizDashboardException;

if (null != ex)
{
BizDashboardException.publish(ex);
e.ExceptionHandled = true;
}

--
Thanks & Regards,
Manjunath T.


Flinky Wisty Pomm said:
Try handling the Selected event of your ObjectDataSource:

protected void ObjectData_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
BizDashboardException ex = e.Exception as BizDashboardException;
if (null != ex)
{
BizDashboardException.publish(ex);
e.ExceptionHandled = true;
}
}



Also, unless you have a _really_ good reason, don't ever do

try
{
...
}
catch(System.Exception ex)
{
DoAbsolutelyNothingWithException(ex);
}

or you won't find out that your app is broken until it's too late.
Manjunath said:
HI,

How to catch custom exception using ObjectDataSource Control.
I am calling Business Layer method through ObjectDataSource control, when
Business layer method throws exception which will be wrapped to custom
exception and thrown. I want to capture the custom exception in UI Layer.

e.g.,
UI Layer Code:
protected void Page_Load(object sender, EventArgs e)
{
try
{
ObjectDataSource1.SelectMethod = "GetAllRoles";

ObjectDataSource1.TypeName =
"Shell.BizTalk.Services.BizDashboard.BusinessLayer.RoleBL";
GridView1.DataSourceID = "ObjectDataSource1";
GridView1.DataBind();
}
catch (BizDashboardException objBizDashboardException) // want to capture Here
{
string s1 = objBizDashboardException.errorNo;
BizDashboardException.publish(objBizDashboardException);
}
catch (Exception ex)
{
string s = ex.InnerException.Message; // Always capture this exception
}


}

Business Layer Code:
public static roleData GetAllRoles()
{
roleData objRoleData = null;
try
{
int x = objRoleData.Tables[0].Rows.Count;
}

catch (Exception objException) // Converting to Custom Exception
{
throw new BizDashboardException("BSC-001", objException,
objException.Message, "RoleBL-GetAllRoles", Severity.Warning);
}
return objRoleData;
}
 
Top