1

Seldom I receive a report from some user that the application has terminated itself with a following message box:

Microsoft C++ Visual Runtime Library

Runtime error!

Program: XXXXX.exe

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Unfortunately the application terminates silenly after showing the message. We have a crash dump generation on structured exceptions, but as there is no exception here, no crash dump is generated.

What can be causing this message?

Is there some way to change the application so that instead of (or in addtion to) showing the message a minidump is generated (or some other custom handling is done by the application)?

Suma
  • 33,181
  • 16
  • 123
  • 191
  • You'll need a minidump to debug this. Ask your user to create one while the dialog is displayed. Task Manager in Vista/Win7 can do it. – Hans Passant Nov 18 '10 at 16:14
  • I would prefer the application to generate a minidump automatically, just like when it crashes. – Suma Nov 18 '10 at 17:43

2 Answers2

4

The message is produced by abort(), which can be called either directly, or by badly designed exceptions - see unexpected() or terminate(), as described in Disable Microsoft Visual C++ Runtime Error. Whether the message is shown or not can be adjusted using _set_abort_behavior call. On XP and later the application should create a minidump by default and send it to Windows Error Reporting service. If you need a custom handler (e.g. custom crash dump), the only (non-standard) possibility seems to be to provide your own implementation for the abort() function.

The default implementation of abort in Microsoft C Runtime Library does following:

  • shows the message box or prints the message to the console
  • raises handler for SIGABRT if there is any
  • if fault reporting is allowed, then
    • deletes any handler for unhandled exceptions using SetUnhandledExceptionFilter(NULL)
    • executes UnhandledExceptionFilter with an artificially prepared exception information
  • calls _exit(3) to terminate the process without any additional cleanup

Including a following code in your source makes the application to perform default structured exception handling (including any filter you may have installed):

extern "C" void __cdecl abort (void)
{
  volatile int a = 0;
  a = 1/a;
}
Community
  • 1
  • 1
Suma
  • 33,181
  • 16
  • 123
  • 191
  • This is summarizing what I have learned so far - thanks to sharptooth for his links and advice. – Suma Nov 22 '10 at 07:33
  • 1
    Do you effecively replace CRT implementation of `abort()` with yours? – sharptooth Nov 25 '10 at 14:26
  • Yes, exactly. Beware: this is non-standard (as defined by standard, if you use system headers, you cannot provide your own implementations of functions defined in those headers), so be sure you understand what are you doing. – Suma Nov 26 '10 at 08:50
3

The application has called abort() most likely because terminate() has been called after an exception has escaped a destructor during stack unwinding or because an exception was not called.

See an answer to this related question for details. Basically you have to catch and handle all exceptions at the top level, not let exceptions escape destructors. Start your program under debugger and enable "Stop when exception is thrown" to find what exactly is going wrong inside and fix that.

Community
  • 1
  • 1
sharptooth
  • 167,383
  • 100
  • 513
  • 979
  • The C++ exception is not enabled in the application. I understand it might be abort() called from someplace else. Is there any other reason? Is there some way to override the processing, to do something else instead of showing the message? – Suma Nov 18 '10 at 14:37
  • @Suma: You can use `_set_abort_behavior()` to suppress message box showing. You can also use `set_terminate()` to replace the `terminate()` handler. And how can C++ exceptions not be enabled? – sharptooth Nov 18 '10 at 14:38
  • Also "Start your program under debugger" is not helpful in my case, as it never happened to me. It happens very seldom, I get this report maybe a few times in a year from some user. – Suma Nov 18 '10 at 14:39
  • @Suma: I see. Still I don't understand how C++ exceptions might not be enabled. – sharptooth Nov 18 '10 at 14:40
  • C++ exception support can be disabled in compiler settings, on the page Code Generation there is option which can be set to No. (My application is a game and it is common in game development not to use exceptions because of performance.) The application never throws a single exception. – Suma Nov 18 '10 at 14:48
  • 1
    @Suma: No, that option doesn't disable exceptions - it only omits code for stack unwinding. See this related question: http://stackoverflow.com/questions/943087/what-exactly-will-happen-if-i-disable-c-exceptions-in-a-project Exceptions are essential for C++ - for example `operator new` can throw an exception and STL will throw exceptions on certain occasions. – sharptooth Nov 18 '10 at 14:51
  • As I wrote, not a single exception is thrown. The application is not using STL. We use custom new which never throws. This means abort() cannot be called from a C++ exception, as they are never thrown. What are other ways for this message to appear? How to override the reaction? – Suma Nov 18 '10 at 15:26
  • @Suma: If `abort()` is called directly I'm afraid you're out of luck. Do you mean that you have inspected all the sources, runtime library included, and not a single exception is ever thrown? – sharptooth Nov 19 '10 at 08:44
  • Yes. Not a single exception is ever thrown. – Suma Nov 22 '10 at 07:25
  • @Suma: Then I guess your best bet is to search the sources for calls to `abort()` - the message actually comes from `abort()` implementation in CRT. I guess you could add some logging or other enhancement that would ease debugging. – sharptooth Nov 22 '10 at 07:31