0

Good Day,

In SAP DI-API integration, I'm receiving the strangest behaviour from COM objects (SAP COM objects).

For the first time in my experience with this (and any) development, I can see a COM object failing to be "Caught" in a try catch block of code.

Again, the behaviour observed is very sporadic. The following is a snippet where this occurs.

try
{
     Children = oGenData.Child("CAMPAIGNLINES");

     if (Children != null)
        if (Children.Count > 0)
           foreach (var line in Children)
              if (line != null) Children.Remove(0);                


     return true;
 }
 catch (Exception ex)
 { //handle exception }

I added some meat around the code to try and support the cause but still, while developing the web project, the Webdav40 server app(which hosts your web project while debugging in visual studios 2010) just crashes as soon as the Children object is accessed for enumeration in the for loop.

This, in my experience has never happened to this object while in QA pahses and only now exhibits this behaviour. The try catch block is completely skipped and execution is stopped.

Has anyone ever experienced such an instance?

Thank you in advance.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Medismal
  • 421
  • 3
  • 18
  • see [What is the best way to modify a list in a 'foreach' loop?][1] [1]: http://stackoverflow.com/questions/759966/what-is-the-best-way-to-modify-a-list-in-a-foreach-loop – Che Jul 23 '15 at 10:24

3 Answers3

0

Just a guess but add another catch clause

catch
{
    // handle exception
}

and also subscribe to AppDomain.UnhandledException. Maybe you get a clou from there what is going on.

Oliver
  • 43,366
  • 8
  • 94
  • 151
0

if oGenData is null you'll catch NullReferenceException

and this block will throw InvalidOperationException:

foreach (var line in Children)
      if (line != null) Children.Remove(0);    

catch (Exception ex) and just catch have become same.

and no, it's not possible to escape from try/catch except StackoverFlowException etc

burning_LEGION
  • 13,246
  • 8
  • 40
  • 52
0

By just glancing the code:

if (line != null) Children.Remove(0);   

I think this is the mistake. You cannot modify the collection when you are looping with it. (enumerating).

Probably in your QA, you don't have any "children" objects (Count of children = 0)

Other reason that this would fail is when there are big collection of children objects and memory overflows.

danopz
  • 3,310
  • 5
  • 31
  • 42
  • Which was my understanding of this too, but actually, I added the `if (line != null)` section to try and determine if the line object in the foreach loop was actually null when the attempt to delete it is made. Which isn't the case. When I step through the code, the app spontaneously fails as soon as the `Children` object is highlighted while stepping though. Once you step once more, the described situation occurs. I have tested to see if the `Children` object is null but that is almost never the case, in which the removal of those lines should not be necessary anyway. – Medismal Jul 23 '15 at 11:58
  • As for the `Children` object not having a count, there is always a count if there are lines added to it. Thanks for that, but I did check explicitly. – Medismal Jul 23 '15 at 11:59
  • As for not being able to modify the `Children` object while looping through it : Welcome to the SAP DI API my friend :D. This is how you run with these COM objects. – Medismal Jul 23 '15 at 12:00