Does .net write a new exception handler every time a try block is opened?

Just read about the first and second random exceptions. And this, when debugging the debugger, gets the first chance exception before executing the program. This is important how the exception handler binding works. Is this the case when every time a try block is opened, another exception handler is added?

+6
source share
2 answers

So I found Junfeng Zhang's great article: "From Unhandled Exception for Debugging Application"

This is called Postmortem debugging options, you can configure the postmortem debugger yourself in the Windows registry when Visual Studio installed the registry key \\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AeDebug contains:

"C:\WINNT\system32\vsjitdebugger.exe" -p %ld -e %ld

So, the Visual Studio JIT debugger is defined as the default postmortem debugger.

Just key points: (see article for more details)

Windows can handle user-mode errors in various ways. The following sequence shows the priority used for error handling:

  • If the user mode debugger is currently connected to the crash process, all errors will cause the target to penetrate this debugger.

  • If no user debugger is connected, and the executable code has its own exception handling procedures (for example, try - except), this exception handling procedure will try to deal with the error.

  • If the user mode debugger is not connected, and Windows has an open connection for debugging the kernel, and the error is breaking the breakpoint, Windows will try to contact the kernel debugger.
+3
source

(fixed) In terms of performance, using try / catch has a small hit of over 2 billion iterations when launched in release mode.

  var watch = new Stopwatch(); watch.Start(); var cnt = 0; for (int i = 0; i < int.MaxValue; i++) { try { cnt++; } catch (Exception ex) { } } watch.Stop(); Console.WriteLine(watch.Elapsed); // takes 00:00:06.25 

and

  var watch = new Stopwatch(); watch.Start(); var cnt = 0; for (int i = 0; i < int.MaxValue; i++) { cnt++; } watch.Stop(); Console.WriteLine(watch.Elapsed); // takes 00:00:00.90 
0
source

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


All Articles