Results 1 to 3 of 3

Thread: [RESOLVED] Which Exception to Use?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Somewhere else today
    Posts
    355

    Resolved [RESOLVED] Which Exception to Use?

    I understand the error message, but I am not sure which exception to use as I want to generate my own error message.

    Code:
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
            
            Try
                Me.Validate()
    
                If RoomSetup.Focus Then
                    Me.RoomCodesBindingSource.EndEdit()
                    Me.RoomCodesTableAdapter.Update(Me.RestelDataSet.RoomCodes)
                End If
    
                If Accounts.Focus Then
                    Me.BudgetTypesBindingSource.EndEdit()
                    Me.BudgetTypesTableAdapter.Update(Me.RestelDataSet.BudgetTypes)
                 End If
    
            Catch ex As System.Data.ConstraintException
                MsgBox("My Own Message of some sort")
    
            End Try
        End Sub
    As you can see I am using an exception but it seems not to be the correct one as I get the message attached not the one I want.

    Any help would be appreciated.

    Computerman
    Attached Images Attached Images  
    It was much easier in VB6, but I am now liking Vb.Net alot more.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: Which Exception to Use?

    The key is the last sentence of the error message. You have to handle the DataError event on the grid.


    Private Sub DataGridView1_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError

    If TypeOf (e.Exception) Is System.Data.ConstraintException Then
    MsgBox("My Own Message of some sort")
    'tell the grid you handled this error
    e.Cancel = True
    End If

    End Sub
    Last edited by Edneeis; Sep 5th, 2009 at 05:02 PM.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Somewhere else today
    Posts
    355

    Re: Which Exception to Use?

    Many thanks for that. I works perfectly.

    Computerman
    It was much easier in VB6, but I am now liking Vb.Net alot more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width