1

Here is the code that should be generating a first chance exception.

class MyClass
{
    public string SomeField { get; set; }
}
class Program
{
    static void Main(string[] args)
    {

        try
        {
            Print(null);
        }
        catch { }

    }


    static void Print(MyClass myclass)
    {
        Console.WriteLine(myclass.SomeField);
    }
}

I setup ProcDump to capture crash dumps as follows.

ProcDump -ma MyApplication.exe

To my understanding, this command should capture first chance and second change exceptions both. However with code above I don't get any exception. If remove the catch block from my code then I do get a dump file but should be a second chance exception. Any ideas why I don't get any crash dump for first chance?

crazy novice
  • 1,757
  • 3
  • 14
  • 36
  • I'm pretty sure that "first chance exceptions" are a debugger thing only. ProcDump is only going to be triggered for exceptions that are unhandled by the application and therefore passed on the operating system. In debugger parlance, those are "second chance exceptions". Why, exactly, do you want to collect dumps of first chance exceptions? Why can't you just debug those using the debugger? – Cody Gray - on strike Aug 22 '14 at 15:02
  • I certainly can that but I want to understand if its possible to capture first chance exceptions. I change the command to ProcDump -ma -e 1 MyApplication.exe which should be capturing first chance also but still don't see any dump file captured. – crazy novice Aug 22 '14 at 15:10
  • Are you running the application with the debugger attached? If so, it's going to pick up the exception first, before ProcDump can get at it. Sounds like you already know more than me, though. I wasn't aware there was an `-e 1` option for ProcDump. :-) – Cody Gray - on strike Aug 22 '14 at 15:11
  • nops, I am not running the application under debugger – crazy novice Aug 22 '14 at 15:14

1 Answers1

3

You are not using it correctly, it isn't shy about telling you that. Change your code to:

static void Main(string[] args) {
    Console.WriteLine("Okay, start ProcDump now and press Enter");
    Console.ReadLine();
    try {
        Print(null);
    }
    catch { }
}

Consider DebugDiag as an alternative.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Actually I had the Console.ReadLine() in my code so that ProcDump can find the process. Sorry I shouldn't have removed that line from the code. – crazy novice Aug 22 '14 at 18:28
  • No, you should have not removed it. This worked fine when I tested it. procdump.exe -ma -e 1 consoleapplication1.exe. Switch and press Enter, bam, 48 megabyte .dmp file. What else don't we know? What does ProcDump actually display? – Hans Passant Aug 22 '14 at 18:34
  • Actually my bad, Console.ReadLine() was at wrong place. You are the man :) – crazy novice Aug 22 '14 at 18:37
  • BTW regarding your suggestion of using DebugDiag, can it be configured against process that is not running? – crazy novice Aug 22 '14 at 18:38
  • To answer @PaulSnow's last question (and this comes many years late, but perhaps might help others) - I haven't found a way to do so in DebugDiag. In my experience the process must still be running while you're creating the rule so you can select it. Thereafter (if the rule is still active) DebugDiag should continue collecting crash dumps for future runs. https://blogs.msdn.microsoft.com/kaushal/2012/05/09/using-debugdiag-to-capture-a-dump-on-first-chance-exception/ – ErrCode Nov 16 '18 at 11:09