“此应用程序已请求运行时以异常方式终止它”的原因是什么?

发布于 2024-12-16 19:59:22 字数 1789 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等往事风中吹 2024-12-23 19:59:22

abort() 时,您会收到该消息函数被调用。

来自 MSDN:

中止

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

void abort(void);

返回值

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

备注

默认情况下,中止例程会打印消息:

“此应用程序已请求运行时以异常方式终止它。请联系应用程序的支持团队以获取更多信息。”

似乎在最新版本的 VC 运行时中,该消息已被替换为“abort() 已被调用”,也许是为了澄清它的真正含义。如果您想重现该消息,请使用旧的 VC 运行时(当然是 VC++ 6.0),并调用 abort()

在内部,当调用 abort() 时,它调用一个函数 _amsg_exit,在internal.h 中定义,它基本上“向控制台应用程序的stderr 发出运行时错误消息,或在Windows 应用程序的消息框中显示该消息”。 “此应用程序已请求运行时以异常方式终止它”的错误消息在 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 中定义:

rterr.h

#define _RT_ABORT  10  /* Abnormal program termination */

因此,您也可以通过调用 _amsg_exit( _RT_ABORT ) 来重现此内容


问题发布者更新:在我提出这个问题两周后,Raymond Chen 在他自己的博客中回答了< /a>:

你正在运行你的程序,然后它突然退出并显示
message 此应用程序已请求运行时终止它
一种不寻常的方式。
发生了什么?

该消息由 C 运行时函数 abort 打印相同的
函数也会导致您的程序
以退出代码终止
3
.

您的程序可能会显式调用 abort,或者最终可能会
由运行时库本身隐式调用。

C++ 标准阐明了终止 的条件
打电话,而且清单很长,所以我不会费心重复它们
这里。有关详细信息,请参阅您最喜欢的 C++ 标准副本。 (这
最常见的原因是引发未处理的异常。)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文