windows “此应用程序已请求运行时以异常方式终止它”的原因是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8177152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the cause of "This application has requested the Runtime to terminate it in an unusual way"?
提问by Ian Boyd
There's a common error that gets thrown by the Visual C Runtime:
Visual C 运行时会抛出一个常见错误:
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
异常:访问冲突 (0xc0000005),地址 0x702be865
This access violationhas 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).
这种访问违规与性骚扰无关,也与有人试图闯入我的计算机无关(除了 General Failure 是一名试图读取我的 C 驱动器的准将,或者您可能会因为执行一项操作而被送进监狱) Windows 95 中的非法操作)。
In this case, access violationcorresponds 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.
在这种情况下,访问冲突对应于常量EXCEPTION_ACCESS_VIOLATION
(winbase.h
用值 0xC0000005声明)。这个常量是一种可以在EXCEPTION_RECORD
结构中返回的可能的异常错误代码。该代码ACCESS_VIOLATION
意味着程序试图读取或写入内存中不应该存在的地址。如果您尝试从从未分配过的内存地址中读取数据,那么您正在做一些非常糟糕的事情 - 异常会告诉您这一点。
It is usuallycaused 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 notasking:
- why is program xgetting a C0000005 error?
- why is my code getting an access violation?
- how do I debug an access violation?
注意:我不是问:
- 为什么程序x收到 C0000005 错误?
- 为什么我的代码出现访问冲突?
- 如何调试访问冲突?
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:
我(相当)确定 Microsoft Visual C 运行时库没有函数:
void TerminateRuntime(bool UnusualWay);
So I have to try to figure out what it actually means:
所以我必须试着弄清楚它的实际含义:
- What does it mean to terminatethe visual C runtime library? (msvcrt is a dll; you don't terminate it, you just don't use it anymore)
- What would be a usualway to terminate MSVCRT?
- Would someone chooseto terminate it in an unusualway?
- Is today's unusualway actually a long since deprecated form of what used to be the usualway?
- If I was(mistakenly) terminating it in an unusual way, what would I do to terminate it in the usualway?
- 终止Visual C 运行时库是什么意思?(msvcrt 是一个 dll;您不会终止它,只是不再使用它)
- 终止 MSVCRT的常用方法是什么?
- 有人会选择以不寻常的方式终止它吗?
- 今天的不寻常方式实际上是过去常用方式的一种早已弃用的形式吗?
- 如果我被(错误地)在一个不寻常的方式终止它,你会怎么做才能终止它在通常的方法是什么?
In other words: what error is the MSVCRT catching, and hiding behind the uninformative error message?
换句话说:MSVCRT 捕获了什么错误,并隐藏在无信息错误消息后面?
采纳答案by JosephH
You get that message when abort()
function is called.
abort()
调用函数时您会收到该消息。
abort
Aborts the current process and returns an error code.
void abort( void );
Return Value
abortdoes 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 abortroutine 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."
中止
中止当前进程并返回错误代码。
void abort( void );
返回值
abort不会将控制权返回给调用进程。默认情况下,它终止当前进程并返回退出代码 3。
评论
默认情况下,中止例程打印消息:
“此应用程序以不寻常的方式请求运行时终止它。请联系应用程序的支持团队以获取更多信息。”
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()
.
似乎在 VC 运行时的最新版本中,该消息已被替换为“已调用 abort()”,这可能是为了阐明它的真正含义。如果要重现该消息,请使用旧的 VC 运行时(当然是 VC++ 6.0),然后调用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:
在内部,当abort()
被调用时,它调用在 internal.h 中定义的函数_amsg_exit,它基本上“将运行时错误消息发送到控制台应用程序的 stderr,或在 Windows 应用程序的消息框中显示消息”。cmsgs.h 中定义了“此应用程序已请求运行时以异常方式终止它”的错误消息:
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:
传入 ( _RT_ABORT
)的错误代码在 rterr.h 中定义:
rterr.h
rerr.h
#define _RT_ABORT 10 /* Abnormal program termination */
So alternatively, you can reproduce this by calling _amsg_exit( _RT_ABORT )
因此,或者,您可以通过调用重现此 _amsg_exit( _RT_ABORT )
Update by question poster: Two weeks after i asked this question, Raymond Chen answered it in his own blog:
问题海报更新:在我提出这个问题两周后,Raymond Chen 在他自己的博客中回答了这个问题:
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 assert macro calls abortwhen an assertion fails.
- By default, the terminate functioncalls abort.
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.)
您正在运行您的程序,然后它突然退出并显示消息此应用程序已请求运行时以一种不寻常的方式终止它。发生了什么?
该消息由 C 运行时函数 abort打印,该函数也会导致您的程序以退出代码 3 终止。
您的程序可能会显式调用 abort,也可能最终会被运行时库本身隐式调用。
C++ 标准阐明了
terminate
调用的条件,而且列表很长,所以我不会在这里重复它们。有关详细信息,请查阅您最喜欢的 C++ 标准副本。(最常见的原因是抛出未处理的异常。)