“此应用程序已请求运行时以异常方式终止它”的原因是什么?
Visual C 运行时抛出一个常见错误:
此应用程序已请求运行时以异常方式终止它。
请联系应用程序的支持团队以获取更多信息。
此错误消息实际上意味着什么??
让我用一个比喻来准确地解释我的问题。
如果我看到一条消息:
异常:访问冲突 (0xc0000005),地址 0x702be865
此访问冲突与性骚扰或试图闯入我的计算机的人无关(一般失败只是一名准将试图侵入我的计算机)读我的 C 盘,否则你可能会因在 Windows 95 中执行非法操作而被送进监狱)。
在这种情况下,访问冲突对应于常量EXCEPTION_ACCESS_VIOLATION
(在winbase.h
中声明,值为0xC0000005)。此常量是一个可能的异常错误代码,可以在 EXCEPTION_RECORD
结构。代码 ACCESS_VIOLATION
表示程序试图读取或写入内存中不应该读取或写入的地址。如果您尝试从从未分配的内存地址中读取数据,那么您正在做一些非常糟糕的事情 - 并且异常告诉您这一点。
通常是当程序的内存指针无效或不再有效时引起的。解决方案是停止尝试访问无效的内存。
注意:我不是问:
- 为什么程序x出现C0000005错误?
- 为什么我的代码出现访问冲突?
- 如何调试访问冲突?
因此,如果我问您,导致访问冲突的原因,您不会告诉我我检查堆栈跟踪,或观察输出窗口,或发布示例代码。您可能会说,“这是由于尝试访问无效的内存。”
回到我的问题
以下错误是什么意思:
此应用程序已请求运行时以异常方式终止。
我(相当)确定 Microsoft Visual C 运行时库没有函数:
void TerminateRuntime(bool UnusualWay);
所以我必须尝试弄清楚它实际上是什么意思是:
- 终止 Visual C 运行时库是什么意思? (msvcrt 是一个 dll;您不会终止它,只是不再使用它)
- 终止 MSVCRT 的通常方法是什么?
- 有人会选择以不寻常的方式终止它吗?
- 今天的不寻常方式实际上是早已被弃用的过去通常方式的形式吗?
- 如果我(错误地)以一种不寻常的方式终止它,我会怎样做才能以通常方式终止它?
换句话说:MSVCRT 捕获了什么错误,并隐藏在无信息的错误消息后面?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当
abort()
时,您会收到该消息函数被调用。来自 MSDN:
似乎在最新版本的 VC 运行时中,该消息已被替换为“abort() 已被调用”,也许是为了澄清它的真正含义。如果您想重现该消息,请使用旧的 VC 运行时(当然是 VC++ 6.0),并调用
abort()
。在内部,当调用
abort()
时,它调用一个函数 _amsg_exit,在internal.h 中定义,它基本上“向控制台应用程序的stderr 发出运行时错误消息,或在Windows 应用程序的消息框中显示该消息”。 “此应用程序已请求运行时以异常方式终止它”的错误消息在 cmsgs.h 中定义:cmsgs.h:
以及传入的错误代码 (
_RT_ABORT
) 在 rterr.h 中定义:rterr.h
因此,您也可以通过调用
_amsg_exit( _RT_ABORT )
来重现此内容问题发布者更新:在我提出这个问题两周后,Raymond Chen 在他自己的博客中回答了< /a>:
You get that message when
abort()
function is called.From MSDN:
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:
and the error code that gets passed in (
_RT_ABORT
) is defined in rterr.h:rterr.h
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: