62

There's a common error that gets thrown by the Visual C Runtime:

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

What does this error message actually mean?


Let me use a parable to explain exactly what i'm asking.

If I see a message:

Exception: access violation (0xc0000005), Address 0x702be865

This access violation has nothing to do with sexual harassment, or someone trying to break into my computer (any more than General Failure was a brigadier general who was trying to read my C drive, or that you could be hauled off to jail for performing an illegal operation in Windows 95).

In this case, access violation corresponds to the constant EXCEPTION_ACCESS_VIOLATION (declared in winbase.h with value 0xC0000005). This constant one possible exception error code that can be returned in an EXCEPTION_RECORD structure. The code ACCESS_VIOLATION means that the program tried to read or write to an address in memory that it shouldn't be. If you try to read from a memory address that was never allocated, then you're doing something horribly bad - and the exception tells you so.

It is usually caused when a program has a pointer to memory that is not, or is no longer, valid. The solution is stop trying to access memory that isn't valid.

Note: I'm not asking:

  • why is program x getting a C0000005 error?
  • why is my code getting an access violation?
  • how do I debug an access violation?

So if I asked you, what causes an access violation, you wouldn't tell me to check the stack trace, or watch the output window, or to post sample code. You would say, "It is from trying to access memory that isn't valid."

Back to my question

What does the following error mean:

This application has requested the Runtime to terminate in an unusual way.

I am (fairly) certain that the Microsoft Visual C Runtime library does not have a function:

void TerminateRuntime(bool UnusualWay);

So I have to try to figure out what it actually means:

  • What does it mean to terminate the visual C runtime library? (msvcrt is a dll; you don't terminate it, you just don't use it anymore)
  • What would be a usual way to terminate MSVCRT?
  • Would someone choose to terminate it in an unusual way?
  • Is today's unusual way actually a long since deprecated form of what used to be the usual way?
  • If I was (mistakenly) terminating it in an unusual way, what would I do to terminate it in the usual way?

In other words: what error is the MSVCRT catching, and hiding behind the uninformative error message?

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • When the message says "terminate it" it means terminate the application, not terminate the runtime. I couldn't find any documentation on MSDN but this message was mentioned in a number of forum threads: the consensus appears to be that it means that an exception was thrown and never caught. – Harry Johnston Nov 18 '11 at 03:38
  • 5
    This question is so fantastically written that I'd upvote and star it even if I didn't happen to find it useful. In particular, I love your proposed declaration for `TerminateRuntime`. (I've taken the liberty of cleaning up a few minor things such as capitalization; I'm impressed that this is as thorough and well-written as it is without a single (non-Ninja) edit before mine.) – Kyle Strand Sep 26 '14 at 20:31

1 Answers1

45

You get that message when abort() function is called.

From MSDN:

abort

Aborts the current process and returns an error code.

void abort( void );

Return Value

abort does not return control to the calling process. By default, it terminates the current process and returns an exit code of 3.

Remarks

By default, the abort routine prints the message:

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

It seems that in the recent version of the VC runtime, the message has been replaced by "abort() has been called" perhaps to clarify what it really means. If you want to reproduce that message, use an old VC runtime( VC++ 6.0 for sure), and call abort().

Internally, when abort() is called, it calls a function _amsg_exit, defined in internal.h, which basically "emits the runtime error message to stderr for console applications, or displays the message in a message box for Windows applications". The error message for "This application has requested the Runtime to terminate it in an unusual way" is defined in the cmsgs.h:

cmsgs.h:

#define _RT_ABORT_TXT  "" EOL "This application has requested the Runtime to terminate it in an unusual way.\nPlease contact the application's support team for more information." EOL

and the error code that gets passed in (_RT_ABORT) is defined in rterr.h:

rterr.h

#define _RT_ABORT  10  /* Abnormal program termination */

So alternatively, you can reproduce this by calling _amsg_exit( _RT_ABORT )


Update by question poster: Two weeks after i asked this question, Raymond Chen answered it in his own blog:

You're running your program, and then it suddenly exits with the message This application has requested the Runtime to terminate it in an unusual way. What happened?

That message is printed by the C runtime function abort, the same function that also causes your program to terminate with exit code 3.

Your program might call abort explicitly, or it might end up being called implicitly by the runtime library itself.

The C++ standard spells out the conditions under which terminate is called, and it's quite a long list, so I won't bother repeating them here. Consult your favorite copy of the C++ standard for details. (The most common reason is throwing an unhandled exception.)

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
JosephH
  • 8,465
  • 4
  • 34
  • 62
  • 3
    You exactly win. That's exactly what the cause of the message is, the programmer called `abort()`. If i want to stop that error the developer has to stop calling `abort()`. – Ian Boyd Nov 18 '11 at 14:24
  • 2
    Good answer. And I want to know how to troubleshoot such error? To be explicite, how to know what exception is uncaught and where it is thrown? – smwikipedia Dec 26 '16 at 01:57
  • In case somebody comes across this like I did (I AM the application support team and couldn't contact myself) wanting to find out how to find who aborted, see this other question for how to create a terminate function that you can put a breakpoint in: https://stackoverflow.com/questions/2443135/how-do-i-find-where-an-exception-was-thrown-in-c – Dtor Jun 28 '18 at 04:37
  • 1
    Is there any way of preventing the message box from being shown? It is much better in many situations to log the error and then terminate directly (without any user interaction) so that the process can be re-started. – Nils Lande Nov 21 '18 at 10:32
  • 2
    Found it. _set_abort_behavior( 0, _WRITE_ABORT_MSG); can be used to get rid of 'the helpful message' as MS calls it ... – Nils Lande Nov 21 '18 at 11:26
  • 1
    [docs for _set_abort_behavior](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/set-abort-behavior?view=msvc-170) – djvg Nov 10 '21 at 09:28