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?