What is the reason "This application asked Runtime to terminate it in an unusual way"?

There is a general error that occurs when executing Visual C Runtime:

This application asked Runtime to terminate it in an unusual way.
For more information, contact support.

What does this error message mean?




Let me use the parable to explain what I ask.

If I see a message:

Exception: Access Violation (0xc0000005), Address 0x702be865

This access violation has nothing to do with sexual harassment or with someone trying to get into my computer (no more than General Failure was a brigadier general who tried to read my C drive, or that you could be sent to jail for execution illegal operation in Windows 95).

In this case, the access violation corresponds to the constant EXCEPTION_ACCESS_VIOLATION (declared in winbase.h with the value 0xC0000005). This constant is one possible exception error code that can be returned in the EXCEPTION_RECORD structure. The code ACCESS_VIOLATION means that the program tried to read or write to an address in memory, which should not be. If you try to read from a memory address that has never been allocated, it means that you are doing something terribly bad - and this explains the exception.

This is usually caused by the fact that the program has a pointer to a memory that is not or is no longer valid. The solution stops trying to access memory that is not valid.

Note : I do not ask:

  • Why is program x getting error C0000005?
  • Why is my code getting an access violation?
  • How can I debug access violation?

So, if I asked you what causes an access violation , you would not tell me to check the stack trace or look at the output window or publish a code sample. You would say, "This is from accessing memory that is not valid."




Back to my question. What the following error means:

This application requested the execution of Runtime in an unusual way.

I'm (honestly) sure that the Microsoft Visual C Runtime library does not have a function:

 void TerminateRuntime(bool UnusualWay); 

Therefore, I should try to figure out what this actually means:

  • What does it mean to complete the C visual runtime library? (msvcrt is a dll, you don't finish it, you just don't use it anymore).
  • What would be the usual way to abort MSVCRT?
  • Anyone choose to terminate it in an unusual way?
  • Today, an unusual way is a really outdated view of what used to be the usual way?
  • If I (by mistake) stopped this in an unusual way, what would I do to end it in the usual way?

In other words: what error is the MSVCRT capture and hiding behind the error message?

+45
language-agnostic windows msvcrt
Nov 18 2018-11-11T00:
source share
1 answer

You will receive this message when the abort() function is called.

From MSDN:

interruptions

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.

Notes

By default, the abort procedure prints a message:

"This application asked Runtime to terminate it in an unusual way. For more information, contact support."

It seems that in the latest version of the VC runtime, the message was replaced with "abort () was called", perhaps to clarify what this actually means. If you want to play this message, use the old VC runtime (VC ++ 6.0 required) and call abort() .

Internally, when abort() is called, it calls the _amsg_exit function defined in internal.h, which basically "emits a runtime error message for stderr for console applications or displays a message in the message box for Windows applications." The error message for โ€œThis application requested Runtime to terminate it in an unusual wayโ€ is defined in 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 support team for more information." EOL 

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

rterr.h

 #define _RT_ABORT 10 /* Abnormal program termination */ 

So you can reproduce this by calling _amsg_exit( _RT_ABORT )




Update on the poster question : two weeks after I asked this question, Raymond Chen answered it on his own blog :

You run your program and then it suddenly exits with message This application requested Runtime to complete it in an unusual way. What happened?

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

Your program may explicitly cause an interrupt or it may turn out to be called implicitly by the runtime library itself.

The C ++ standard sets out the conditions under which terminate is a rather long list, so I wonโ€™t repeat them here. See your favorite C ++ standard for more details. (The most common reason is throwing an unhandled exception.)

+35
Nov 18 2018-11-11T00:
source share