Exceptions that are thrown are first chance exceptions. Since your program does not crash, this means they are caught and handled.
In addition to @magicandre1981's approach, I see two other options:
ProcDump
ProcDump can create crash dumps on first chance exceptions with the -e 1
command line switch. Also define -n
to specify the maximum number of dumps you want to take. Once you became aware of an exception and no longer want it to be reported, use -f
to filter it.
Advantage: you do not only have the exception, you also have a call stack and all the heap information which you can analyze later.
Disadvantage: this will significantly slow down your process and take a lot of disk space.
WinDbg exception commands
You could attach WinDbg to a process and use the sxe
command with the -c
switch to analyze first chance exceptions. Include g
in the command to continue execution. It's helpful to write all output into a log file (use .logopen
).
Example:
.symfix
.reload
.logopen c:\debug\logs\firstchance.log
.loadby sos clr
ld *
sxe -c "!pe;!clrstack;g" clr
g
.symfix
and .reload
may not be necessary. Just make sure your symbols are correct, otherwise all the analysis may be useless. The ld *
will just pre-load things to make the analysis faster later on.
Advantage: you can capture as many information as you want without creating huge crash dumps.
Disadvantage: The execution of commands may significantly slow down the process. WinDbg may become unstable when you do this with hundreds of exceptions. (I never did this for a long time, this warning is given based on my experience with WinDbg 6.12 somewhen in 2010)