views:

40

answers:

1

A developer has created a custom control in ASP.NET using VB.NET. The custom control uses a repeater. In certain scenarios, the rpt_ItemDataBound event is encountering a data error. My goal is rather than having the user see the yellow screen of death, give the user a friendlier error explaining exactly what the data error is. I figured I would be able to use a Try/Catch block as shown below throw the exception, however, it appears that the event has nowhere to be thrown to and stops executing at the "End Try" line.

Protected Sub rpt_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rpt1.ItemDataBound, rpt2.ItemDataBound

    Try

        ProcessBadData...

    Catch ex As Exception
        Throw ex
    End Try

End Sub

In VB.NET, I can find where the repeater's DataSource is being set, however, I can not find a DataBind event.

Any ideas how I can capture the exception in this ASCX control so I can report it to the user?

Edit:

The stack trace looks like this. There is another repeater within the repeater that is actually causing the error (rptOther) and I'm able to catch the error, but I can only throw it to the rpt_ItemDataBound. I can't figure out how rpt_ItemDataBound is getting called without a DataBind event.

at Company.WebForms.Control.rptOther_ItemDataBound(Object sender, RepeaterItemEventArgs e)
at System.Web.UI.WebControls.Repeater.OnItemDataBound(RepeaterItemEventArgs e)    
at System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem)    
at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)    
at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)    
at System.Web.UI.WebControls.Repeater.DataBind()    
at Company.WebForms.Control.rpt_ItemDataBound(Object sender, RepeaterItemEventArgs e)
A: 

Have you tried registering a global exception handler? If you can catch the exception there you can use the stack trace to pinpoint where you might try to catch it properly.

Hadn't thought to look in the exception's StackTrace. Thanks for the idea.
proudgeekdad