Visual Studio Debugging Prevention with Explicit "Unhandled Exception"

Please review this console application shortcode.

static void Main(string[] args) { try { Action a = () => { throw new ApplicationException("Oops"); }; var ar = a.BeginInvoke(null, null); ar.AsyncWaitHandle.WaitOne(); try { a.EndInvoke(ar); Console.WriteLine("No message"); } catch (Exception e) { Console.WriteLine(e.Message); } } finally { Console.ReadKey(); } } 

When launched, Visual Studio will be broken into throw , complaining that its raw. When executed outside the debugger, the code does what I expect (displays "Oops").

How to convince Visual Studio to allow code execution, as it would in the real world?

+6
source share
1 answer

You can apply the DebuggerNonUserCode attribute to a method to hide it from the debugger.

+2
source

Source: https://habr.com/ru/post/898819/


All Articles