Grasshopper

algorithmic modeling for Rhino

Hi david,

Here is a small annoyance in C# components, having a wrong index in .net list/array/collection always shows line 0 in the error message:

code:

    List<object> testFailure = new List<object> ();
    A = testFailure[3];

In this case finding the bug is trivial, but when dealing with dozens of lines of code it's a bit annoying, especially since it's one of the most occurring bugs.

A workaround for this problem is to wrap the code in a try catch, and rethrow the exception with a stack trace:

try {

     List<object> testFailure = new List<object> ();
     A = testFailure[3];

} catch (Exception e)

{

      throw new Exception(String.Format("Exception: {0} Trace: {1}",e.Message, e.StackTrace);

}

Views: 359

Attachments:

Replies to This Discussion

Thanks for this!

I got used to this error, and usually found the prob quite fast. But that's a great workaround.

Thanks.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service