What is the cause of "This application has requested the Runtime to terminate it in an unusual way"? What is the cause of "This application has requested the Runtime to terminate it in an unusual way"? windows windows

What is the cause of "This application has requested the Runtime to terminate it in an unusual way"?


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.)