Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent debugger from stopping on an Exception in a Compiled LambdaExpression

In my program, I create dynamic lambda expressions and then compile them to delegates. These delegates are then invoked to extract information from my entities. Some of the delegates may throw exceptions, I've caught the exception where I call the delegate. I've enabled "Enable just my code" and applied [DebuggerNonUserCode] attribute to where the LambdaExpression is created, where compiled, and where Called. But because in Debug>Exceptions>Common Language Runtime Exceptions, the Thrown check box is checked, visual studio always stops on the error, which is a major inconvenience for the developers.

It seems that [DebuggerNonUserCode] should somehow be applied to the compiled delegate, but how? Or any other suggestion?

Thanks.

like image 729
Alireza Avatar asked Jun 25 '12 05:06

Alireza


People also ask

How do I stop Visual Studio from breaking on exception?

When the debugger breaks, it shows you where the exception was thrown. You can also add or delete exceptions. With a solution open in Visual Studio, use Debug > Windows > Exception Settings to open the Exception Settings window. Provide handlers that respond to the most important exceptions.

How do I break all exceptions in Visual Studio?

From Visual Studio 2015 and onward, you need to go to the "Exception Settings" dialog ( Ctrl + Alt + E ) and check off the "Common Language Runtime Exceptions" (or a specific one you want i.e. ArgumentNullException ) to make it break on handled exceptions.


1 Answers

As far as I know, you cannot apply attributes to anonymous methods generated using expressions, aside from possibly some horrible messing around with dynamic type generation.

However, a possible suggestion would be to go to the exception menu in Debug > Exceptions and choose which exceptions you want to break on specifically. If your expressions tend to throw exceptions of specific kinds, you can just disable breaking on those exceptions.

like image 151
GregRos Avatar answered Oct 21 '22 13:10

GregRos