“此应用程序已请求运行时以异常方式终止它"的原因是什么? [英] What is the cause of "This application has requested the Runtime to terminate it in an unusual way"?

查看:2827
本文介绍了“此应用程序已请求运行时以异常方式终止它"的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual C运行时会引发一个常见错误:

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.

如果我看到一条消息:

例外:访问冲突(0xc0000005),地址0x702be865

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

访问冲突与性骚扰或试图闯入我的计算机无关(除了General Failure是一位准将,他试图读取我的C盘,或者您可能会因为在Windows 95中执行非法操作而被判入狱.

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

在这种情况下,访问冲突对应于常量EXCEPTION_ACCESS_VIOLATION(在winbase.h中声明,值为0xC0000005).此常量可能会在 EXCEPTION_RECORD 结构.代码ACCESS_VIOLATION表示程序试图读取或写入不应该的内存中的地址.如果您尝试从一个从未分配的内存地址中读取数据,那么您所做的事情非常糟糕-异常告诉您.

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.

注意:我不是不是询问:

  • 为什么程序 x 出现C0000005错误?
  • 为什么我的代码遇到访问冲突?
  • 如何调试访问冲突?
  • 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:

该应用程序已请求运行时以异常方式终止.

我(相当)肯定Microsoft Visual C Runtime库没有功能:

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:

  • 终止可视化C运行时库是什么意思? (msvcrt是一个dll;您不会终止它,只是不再使用它)
  • 终止MSVCRT的常用方式是什么?
  • 有人会选择异常的方式终止它吗?
  • 今天的不寻常方式实际上是早已不推荐使用的,过去曾经是常规方式的形式吗?
  • 如果我(错误地)以一种不寻常的方式终止了它,我该怎么做才能以正常的方式终止它?
  • 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?

换句话说:MSVCRT捕获了什么错误并隐藏在无意义的错误消息后面?

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

推荐答案

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

来自MSDN:

中止

中止当前进程并返回错误代码.

abort

Aborts the current process and returns an error code.

void abort( void );

返回值

中止不会将控制权返回给调用过程.默认情况下,它将终止当前进程并返回退出代码3.

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.

默认情况下,中止例程会显示以下消息:

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

在最新版本的VC运行时中,该消息似乎已被已调用abort()"所取代,也许是为了阐明其真正含义.如果要重现该消息,请使用旧的VC运行时(肯定是VC ++ 6.0),然后调用abort().

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

在内部,当调用 abort() 时,它会调用函数 _amsg_exit ,在internal.h中定义,基本上发出运行时错误消息发送到stderr以获取控制台应用程序,或者在Windows应用程序的消息框中显示该消息.在cmsgs.h中定义了此应用程序请求运行时以异常方式终止它"的错误消息:

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

,传入的错误代码(_RT_ABORT)在rterr.h中定义:

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

rterr.h

#define _RT_ABORT  10  /* Abnormal program termination */

因此,您也可以调用_amsg_exit( _RT_ABORT )

按问题发帖人更新:我问了这个问题两周后,雷蒙德·陈(Raymond Chen)回答了自己的博客:

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?

该消息是通过C运行时函数中止打印的,相同的 该函数还会导致您的程序以退出代码终止 3 .

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 abort when an assertion fails.
  • By default, the terminate function calls abort.

C ++标准阐明了terminate的条件 叫,而且名单很长,所以我不会再重复 这里.有关详细信息,请查阅您最喜欢的C ++标准副本. (这 最常见的原因是抛出未处理的异常.)

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

这篇关于“此应用程序已请求运行时以异常方式终止它"的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆