# generating tracebacks for first chance exceptions

Recently I was debugging some workflow where it appeared quite slow. As part of debugging i saw it Visual Studio printed debugging information about first chance exceptions thrown.

Now that David Kline from MS has made it ample clear that FirstChance exceptions are normal exceptions just that debugger gets first chance at them- thus first chance. If debugger chooses not to do anything then application gets a chance to do something about it. If application does not handle it then debugger gets a second chance, thus second chance exceptions. you get the idea.

Now an application can throw as many exceptions it wants and catch it later. This is fine but exceptions are supposed to exceptional and cost quite a bit. (link1 & link2)

I have seen lexical_cast being the one that throws exceptions just to parse strings, with xml parsing this could be a big source of exceptions. One of the ways to speed up applications is now to fix or atleast reason about these exceptions being thrown, and having tracebacks makes life lot easier.

To generate tracebacks is you could use Vectored Exception Handling or windbg. Off course I chose windbg so I set out to generate tracebacks. In my case I recorded 168K+ exceptions thrown out of which I believe ~165K could be filtered.

Anyway, as usual I started windbg with a log file option, as traces could get really large and I did not want to lose any.

windbg -pn testapp.exe -loga d:\tracebacks.txt

Once I had application running, next I ensured that I am listening to correct exception code. In my case it is C++ exception with code e06d7363, some details here and here.

(3770.35a0): Break instruction exception - code 80000003 (first chance)
ntdll!DbgBreakPoint:
00000000779aafb0 cc              int     3
0:008> g
ModLoad: 000007fedcb10000 000007fedcb17000   C:\windows\system32\SHFolder.dll
;
;
(3770.378c): C++ EH exception - code e06d7363 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
KERNELBASE!RaiseException+0x39:
00 000000000022cd80 000007fef65a4572 KERNELBASE!RaiseException+0x39