1

My program runs for about 10 hours during the night, sometimes I wake up to see that it has crashed (for whatever reason). It is usually a "Program Name" has stopped working, and the only button there is to close the program. I have tried watching and waiting for it to crash but the problem seems very hard to reproduce (and I can't watch it 24/7). I have used try and catch statements in my program in potentially problematic areas and told the program to dump to a text file if it catches an exception. But this isn't good enough it seems.

TLDR: Is it possible to tell my program to run a particular function when an exception has been detected in the program in general (without specifics) so that I can dump the stacktrace to a text file and investigate later?

user3494322
  • 171
  • 3
  • 11
  • 1
    Have you looks what the application event log files give? You could also output a log yourself at specific points in your code so that when it fails you will see how far and at which point it fails. You may have to do this several times to see if the failure is at the same point each time. Very little to go on at the moment. – Mych Jul 15 '14 at 15:11
  • Is this Winforms, WPF, or something else? – SeraM Jul 15 '14 at 15:12

2 Answers2

4

Is it possible to tell my program to run a particular function when an exception has been detected...

Yes, but the specifics depend on the platform that you are using:

Community
  • 1
  • 1
Heinzi
  • 167,459
  • 57
  • 363
  • 519
1

It's generally not a good idea to do this. You could, however, look at AppDomain.UnhandledException. This is pretty much restricted to one domain, and you'll also receive (potentially) notifications for all unhandled exceptions unrelated to your program.

This is usually used for class libraries, but I think with a bit of fiddle, you might get it to work.

Wolfish
  • 960
  • 2
  • 8
  • 34