none
Throwed exceptions in Rowdeleted handler are lost RRS feed

  • Question

  • Hi,

    I have found that throwing an exception in a RowDeleted event handler (of a DataTable) doesn't always propagate up to your exception handling logic. This is of course very dangerous. Have I missed something or is this really the way it is supposed to work?

    I checked the disassembled DataTable code (using Reflector) and saw something that might cause this behaviour (code from the SetNewRecordWorker method) :

     

        Try
            If fireEvent Then
                Me.RaiseRowChanged(args, row, action)
            End If
        Catch exception As Exception
            If Not ADP.IsCatchableExceptionType(exception) Then
                Throw
            End If
            ExceptionBuilder.TraceExceptionWithoutRethrow(exception)
        End Try

     

    This indicates that there are some exceptions that are not rethrown and others that are.

     

    Friend Shared Function IsCatchableExceptionType(ByVal e As Exception) As Boolean
        Dim c As Type = e.GetType
        If ((((Not c Is ADP.StackOverflowType) AndAlso (Not c Is ADP.OutOfMemoryType)) AndAlso ((Not c Is ADP.ThreadAbortType) AndAlso (Not c Is ADP.NullReferenceType))) AndAlso (Not c Is ADP.AccessViolationType)) Then
            Return Not ADP.SecurityType.IsAssignableFrom(c)
        End If
        Return False
    End Function

     

    So I tried to throw some other exceptions from my eventhandler, for instance NullReferenceException and StackOverflowException. These are rethrown as you might expect from all exceptions thrown...

     

    Tomas Edström.

    Friday, November 16, 2007 12:16 PM