none
How to catch MFC Application error causing application closing

    Question

  • Probably most of us have seen the dialog box with the following message:

    (AppName) MFC Application - (App description) has encountered a problem and needs to close.  We are sorry for the inconvenience.

    If you were in the middle of something, the information you were working on might be lost.

    Please tell Microsoft about this problem.

    ...

    I have added many try and catch traps, but have not been able to catch this error.  Could anyone offer some tip?

    Thanks,

     

     

     

    Tuesday, February 20, 2007 3:24 PM

Answers

  • Among the best solutions is a careful reveiw of the code to ensure that all errors are caught, reported and proper corrective action is taken (such as exit after reporting if there is nothing else that can be done). The error you are encountering is likely due to an error that is ignored. Also check to ensure that memory is not being clobbered. Check to ensure that array bounds and such things are not being exceeded.

    If you must diagnose the problem in a production execution, I would probably create a log file of some type in which I wrote debugging type of data to. The primary purpose would be to isolate the problem to more specific portions of code. Hopefully the last line or nearly the last line would be written from the area of code preceding the problem. When the problem is determined to be in a certain area, you can put additional monitoring output in that area and remove it from other areas. This is less likely to be effective if the problem is something such as memory corruption.

    Wednesday, February 21, 2007 12:16 PM

All replies

  • If you run your application in the debugger (and have PDB files in the same folder as the application), then it will crash at the line of code your application is having a problem at.
    Tuesday, February 20, 2007 4:49 PM
  • Ted, thanks. 

    That will be my last resort, maybe the only one.  This is an application for internal use (reliability test).  The error happens randomly.  Normally the application will run one to two weeks before this error kills it.  It uses resources intensively due to high data volume and traffic between the application and a local SQL server.

     

     

    Tuesday, February 20, 2007 6:36 PM
  • Among the best solutions is a careful reveiw of the code to ensure that all errors are caught, reported and proper corrective action is taken (such as exit after reporting if there is nothing else that can be done). The error you are encountering is likely due to an error that is ignored. Also check to ensure that memory is not being clobbered. Check to ensure that array bounds and such things are not being exceeded.

    If you must diagnose the problem in a production execution, I would probably create a log file of some type in which I wrote debugging type of data to. The primary purpose would be to isolate the problem to more specific portions of code. Hopefully the last line or nearly the last line would be written from the area of code preceding the problem. When the problem is determined to be in a certain area, you can put additional monitoring output in that area and remove it from other areas. This is less likely to be effective if the problem is something such as memory corruption.

    Wednesday, February 21, 2007 12:16 PM
  • Thanks, Sam!

    Here is the story about the endeavor to catch this nasty bug or something else:

    I have some sense about where the problem is - timer.  One of the timers generates 20 messages every second. The timer handler does quite some work.  My try and catch blocks have caught things such as the handler being invoked again before it finishes (I do not know how this is possible).  The reason I posted this question is I was wondering if it is possible to have an error that cannot be caught by try and catch block, not even by try{} catch{...}.  I have noticed when this error occurs, the thread with timer stops working, but other threads still work fine in the background.  I have put try and catch bloack at every possible place related to the timer. Once I nail down this, I will share the outcome here.  It may take many weeks.

     

     

    Wednesday, February 21, 2007 3:53 PM