468,537 Members | 2,412 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,537 developers. It's quick & easy.

help needed on ObjectDataSource control

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(objBizDashboardExcep tion);
}
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;
}
--
Manjunath T.
Oct 5 '06 #1
2 2807
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 wrote:
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(objBizDashboardExcep tion);
}
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;
}
--
Manjunath T.
Oct 5 '06 #2
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" wrote:
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 wrote:
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(objBizDashboardExcep tion);
}
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;
}
--
Manjunath T.

Oct 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Ole M | last post: by
2 posts views Thread by J055 | last post: by
2 posts views Thread by planetthoughtful | last post: by
10 posts views Thread by J055 | last post: by
8 posts views Thread by Greg Lyles | last post: by
4 posts views Thread by Jonathan Wood | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.