title: C++ program exited with code 0 error
body: <p>I'm doing c++ at my job for the first time in years and am trying to track down a problem. I wrote code that goes out and enumerates the processes running on a machine and returns performance metrics. My problem is that some sort of unhandled error occurs and in the debug window I get a message saying the program has exited with code 0. Here is the code in the main function</p>
  
  <pre><code>    int _tmain(int argc, _TCHAR* argv[])
      {
          while(nRun == 1)
          {
              try
              {
                  WriteHeartBeat();
                  DoProcessLoop(dwTotalRAM, nCheckPause, oPMeter, cFileName, oProcess, oCPUUsage, nProcCount, ddsCaps2, lpDD);
                  CopyPerfFileToDest(cFileName);
                  nRun = 1;
                  tEnd = time(NULL);
              }catch(...){
                  AddToLog("Error in Main Function");
              }
          }
  
      AddToLog("App Stopped");
      return 0;
      }
  </code></pre>
  
  <p>The program runs for a long time but after a while it just comes back saying it exited with code 0 but that "App Stopped" line is never printed into the log.  Does anyone know what kind of error I could have or what issue could be occuring?  Is that try catch block sufficient enough to catch any error that could occur or is there something else I could do. Any help you could offer would be really appreciated.</p>
  
  <p>EDIT: The log file should get 3 entries from here if it exits correctly. They are "Doing Process Loop" for the the "DoProcessLoop" Function, "Copying File" for the "CopyPerfFileToDest" function and the "App Stopped" if it stops correctly. When I make it stop correctly myself I get all 3 lines, when it is stopping incorrectly I only get "Doing Process Loop" in the log and then it exits with code 0. The error must be in there. I was curious if there is a generic error trap I can do to catch any all errors.</p>