Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Just reading about first and second chance exceptions. And that a when debugging the debugger gets the first chance exception before the program does. That in mind how does attaching the exception handler work. Is it a case that every time a try block is opened another exception handler is attached?

like image 584
Exitos Avatar asked Oct 19 '11 10:10

Exitos


1 Answers

Here is I found the great article by Junfeng Zhang's: "From Unhandled Exception to Debugger Attach"

This is called Postmortem debugging settings, you can setup postmortem debugger your self in the Windows System 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 Visual Studio JIT debugger is defined as default postmortem debugger.

Just key points: (for fulld details see article)

Windows can handle user-mode errors in a variety of ways. The following sequence shows the precedence used for error handling:

  1. If a user-mode debugger is currently attached to the faulting process, all errors will cause the target to break into this debugger.

  2. If no user-mode debugger is attached and the executing code has its own exception handling routines (for example, try - except), this exception handling routine will attempt to deal with the error.

  3. If no user-mode debugger is attached, and Windows has an open kernel-debugging connection, and the error is a breakpoint interrupt, Windows will attempt to contact the kernel debugger.
like image 97
sll Avatar answered Oct 16 '22 05:10

sll