Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of things to check to prevent VC++ applications from showing fatal error message boxes

Every now and then there's a strong need to write a program in such a way that it never (really never) shows an error message as a message box. For example it can be a program run inside a daily build - if it hangs with a message box the daily build hangs.

Unfortunately VC++ runtime has a lot of ways to trigger message boxes when indicating errors.

First of all, whenever an exception is not handled terminate() is called which calls abort() which causes "This application has requested the Runtime to terminate it in an unusual way." message box. This can be worked around by catching all exceptions and/or using set_terminate() to set a custom terminate() handler without message boxes.

Then, whenever an exception escapes any destrutor during stack unwinding terminate() is also called. set_terminate() helps here as well.

Then, there's a "pure virtual function call" message box that is shown in some hardcore cases of mismatching the number of functions expected by the caller and those implemented by the callee. _set_purecall_handler() should help here.

What else to do to a VC++ program to be absolutely positively sure it doesn't show a message box in some fatal situation?

like image 455
sharptooth Avatar asked Dec 25 '09 14:12

sharptooth


2 Answers

I would recommend that you use a helper program to launch it and have this helper limit the time your program can run. This is by far the safest way if you can do it, as it handles every case. Some things you cannot handle in your program directly, such as "This program is not a valid Win32 application" which might happen if you are missing a DLL.

like image 171
Dark Falcon Avatar answered Sep 18 '22 03:09

Dark Falcon


Hook the MessageBox API before daily build.

BTW, i think SetUnhandledExceptionFilter. is a relevant API.

like image 21
whunmr Avatar answered Sep 22 '22 03:09

whunmr