none
Check if email to be processed exists, error Error while processing emails .-2147352567 Array index out of bounds. RRS feed

  • Question

  • Hi

    I have 2 task scheduler process running to read the email and execute the same inbox.

    There is a delay with start of the two task process, but I process quite some volume of email in that inbox everyday.

    Sometimes when I run the second job receive the following error

    Error while processing emails .-2147352567 Array index out of bounds.

    Is there any other method, than the highlighted below to handle this. This always catches the oI Exception

                    Dim oItems As Outlook.Items = oInboxFolderLT.Items

                    iItemsCount = oItems.Count

                    Do While True
                        If oItems.Count <= 0 Or
                           iItemsCount <= 0 Then
                            Exit Do
                        End If

                        ' Loop each unread message.
                        Dim oMsg As Outlook.MailItem = Nothing
                        Dim oMsgReportItem As Outlook.ReportItem = Nothing

                        Try
                            If IsNothing(TypeName(oItems.Item(oItems.Count))) Or_

                                IsError(TypeName(oItems.Item(oItems.Count))) Then

                                   iItemsCount = iItemsCount - 1
                                   Continue Do
                            Else
                            End If

                        Catch oi As Exception
                            iItemsCount = iItemsCount - 1
                            Continue Do
                        End Try

                        If FindMatch(TypeName(oItems.Item(iItemsCount)), "ReportItem") Then
                            oMsgReportItem = oItems.Item(iItemsCount)
                            oMsgReportItem.Move(oInboxFolderCSR)

                            'this was added to resolve the server administrator error message
                            oMsgReportItem.Close(Outlook.OlInspectorClose.olDiscard)
                            FinalReleaseComObject(oMsgReportItem)
                            oMsgReportItem = Nothing
                        Else
                            oMsg = oItems.Item(iItemsCount)

                            Do the necessary processing

                        End if

                         iItemsCount = iItemsCount - 1

                     Loop

                End Do

    Monday, November 5, 2018 10:20 PM

All replies

  • Hi,

    Do you want to replace the code below to avoid exceptions?

     Try
                            If IsNothing(TypeName(oItems.Item(oItems.Count))) Or_
    
                                IsError(TypeName(oItems.Item(oItems.Count))) Then
    
                                   iItemsCount = iItemsCount - 1
                                   Continue Do
                            Else
                            End If
    
                        Catch oi As Exception
                            iItemsCount = iItemsCount - 1
                            Continue Do
                        End Try

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 6, 2018 11:32 PM