none
Object Data Source Exception Handling RRS feed

  • Question

  •  

    I'm not sure if this is the correct forum but it's the closest I could find.

     

    I have an object data source on my aspx page that points to a class. The class has public properties which contain validation like the one below.

     

    Code Snippet

    Public Property sState() As String

    Get

    Return m_sState

    End Get

    Set(ByVal value As String)

    If value.Length > 2 Then

    Throw New Exception("State cannot be more than 2 characters")

    Else

    m_sState = value

    End If

    End Set

    End Property

     

     

    When the user enters a state with more than two characters the exception above is thrown and the user sees a screen like this...

    Server Error in '/Williams_Website' Application.

    State cannot be more than 2 characters

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Exception: State cannot be more than 2 characters

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    My question is how do I trap the error. I see no option to do this and the examples on MSDN don't cover exception handling as far as I can see.

    Thanks

    Terry Hutt

    Tuesday, September 4, 2007 7:33 PM

All replies

  • You can use the folowing events to catch the exception (use the corresponding to each case):

    • Selected
    • Inserted
    • Updated
    • Deleted

    Example with Selected:

        Private Sub ODS_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ODS.Selected
            If e.Exception IsNot Nothing Then
                ' Handle the exception
                ' ...
                e.ExceptionHandled = True
            End If
        End Sub
    


    Daniel

    Tuesday, March 13, 2012 1:36 AM