how to attach to debugger in-process
Hello,
I would like to catch all the excpetions in my application (handled + unhandled excpetion) and write to to a trace i have.
The catching should be in-process (from the executable code).
I know how catch the unhandled exceptions (registering to the event in the appDomain).
What i need to know is how to register to the HANDLED exceptions.
Many thanks,
Eran.
[411 byte] By [
eran] at [2008-2-27]
The ability for a process to detect handled exceptions is very dangerous. The concept is called the Vectored Exception Handler on windows. You can do this in unmanaged code with kernel32!AddVectoredExceptionHandler, but it is not supported for managed code. See explanation here for details. Basically, it's too dangerous in managed. (My understanding is that you're asking what your options are with the current design; we can have a whole separate discussion about the design
)
There's no easy way to detect all handled exceptions. If you want this, options include:
1. Use debugging interfaces, which must operate from a 2nd process. Example here.
2. Use profiler interfaces, which have callbacks for managed exceptions. This is hard too (profilers must be written in unmanaged code), but very powerful.
3. The rocket scientist approach is to use kernel32!AddVectoredExceptionHandler, but that's very dangerous and limited, and can't call back into managed code.