Visual Studio Debugging - Break on GH Warning or GH Error


(George Adamon) #1


I’m developing a plug-in in VS 2017 using the GH Assembly Wizard for v6.
Setting up breakpoints in my code works perfectly, just as expected and described in other posts in this forum.

However, I am wondering if it is possible at all for the debugger to automatically break when grasshopper raises an Error (component turns red) or a Warning (component turns orange), for example when the wrong Type is connected to an input (error), or an Invalid Cast is performed (error), or when a parameter exceeds the parameter range (warning) or when an input is left without data (warning) etc etc.

I have tried tweaking various settings inside VS, without luck. The grasshopper runtime warnings/errors are ignored by VS no matter what I do. At the moment:

  • COFF loading in GrasshopperDeveloperSettings is disabled

  • All of the Exceptions in VS Exception Settings are enabled

  • Just-My-Code in Debug Settings is enabled

  • “Enable native code debugging” in MyProject>Properties>Debug is enabled

  • “Treat Warnings as Errors” in MyProject>Properties>Build is set to “All”

My test file contains an intentionally invalid cast from Double to Float, and the component turns red, but the debugger never receives an Exception, and thus it never breaks.

Any help would be appreciated!

(David Rutten) #2

No the SolveInstance and CollectData methods are always called from within a try…catch block, and many warnings and some errors aren’t even associated with exceptions. Furthermore there’s no event associated with strings being pushed onto the error and warning stacks.

If you want to catch your own exceptions inside SolveInstance you can put your code inside a try…catch block. That way you get first dibs at handling any exceptions. But that will not work for errors that come from failed data conversion in input parameters.

(George Adamon) #3

Thanks a lot David for the quick reply! It’s all clear now.

On a side note, do you see a point in implementing some form of this functionality in a future release?

Have a nice day!

(Nathan 'jesterKing' Letwory) #4

Once Rhino and GH have started you can also turn on an automatic break on all exceptions. I use that when debugging my own GhShaderNodes project. It’ll catch all .NET / CLR exceptions (turn off those you are not interested in).

Debug > Windows > Exception Settings | Common Language Runtime Exceptions.