Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sniff a caught exception in .NET on production machine?

Is there a way to find what exception was caught by .NET code from the outside of the application?

I found that 3d party API throws an exception and suppresses it (I see the perf counter going up).

But it doesnt shows it in trace (I tried sysinternals dbgView).

What tool can show a caught exception?

like image 879
Boppity Bop Avatar asked Jan 23 '26 03:01

Boppity Bop


1 Answers

The tool I always turn to in this situation is WinDBG. Download the 32bit version or the 64bit version, depending on the bitness of the process.

For some lame reason the latest version does not have a direct download link (only available in the SDK), so skip down to the 'Previous Version' section and grab the latest of those.

Load WinDBG after installing and do the following:

  1. File -> Attach to a process (F6)
  2. Select the target process and click 'Open'
  3. In the console enter the following:
  • .loadby sos mscorwks (this loads the .NET debugger extensions) - sxe clr (tells the debugger to break on managed exceptions) - g (GO!)
  1. Run the process until the exception occurs.
  2. The debugger will break, at which time enter !pe to see the exception details.

The !clrstack command is useful to see the managed stack or try !dumpstack to include native calls.

If the debugger stops on an exception you don't care about, just hit 'g' again until you get the one you want to see.

The !help command will show all the .NET extensions available and, if you wish to dig deeper, I highly recommend Tess Ferrandez's blog.

like image 128
Kevin Pullin Avatar answered Jan 25 '26 20:01

Kevin Pullin