0

我有一个 C CLI 程序在 Windows 7 中崩溃并生成此错误:

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

首先,我在某处读到它可能是assert触发语句的原因,因此作为第一个措施,我将它们替换为 if 语句以捕获并记录任何潜在的失败断言。其次,我用语句喷洒代码printf以查看程序退出的位置。第三,我特别确保代码不会在没有先记录退出的情况下退出任何地方。该程序是线程化的,因此发生了很多事情,但没有什么太复杂。

现在的问题是,我第二次收到错误时,它表明程序在我的printf语句之外退出,所以我不知道它在哪里退出。

所以两个问题:

  1. 我怀疑我需要使用适当的调试器来查看有关退出的更多详细信息,如果是这样,哪个?
  2. assert除了陈述之外,还有其他关于这种错误的问题吗?我发现很多C++关于这个错误的博客条目,但不是太多C

我正在使用 Visual C++ 2008 速成版。另外,我正在调用CMD.exe.

4

2 回答 2

1

首先,您删除了assert通常用于帮助追踪程序员做出的假设不成立的情况的调用?真的吗?嗯……

其次,您是否熟悉调试器?Visual C++ 应该包含一个集成的调试器,当你的程序在调试模式下运行时,它不仅可以显示你的进程从哪里退出,可以准确地显示你的程序在哪里崩溃,它是如何到达那个点的,以及崩溃时的变量。设想!

本文主要讨论C#,但原理是相同的。

于 2013-04-26T05:55:37.937 回答
0

The message you are getting is from the VC runtime. It happens when an exception is thrown and not caught anywhere.

Compile your program with a debugging debugging configuration (that should be the default) and run in the debugger, and when you hit an unhandled exception, the debugger will break. Under the "Debug" menu, you will find an "Exceptions" item, which will help you fine tune how the debugger responds to exceptions.

Note that in the context of C++ and Windows, 'exception' can mean one of several things; there are the Win32 exceptions, the C++ exception, and VS Structured Exception Handling.

assertions are for fail conditions that you never expect to happen, but can't prove can't happen. You should always be surprised by an assertion. Many (most? all?) implementations of assert() are only compiled in debug configurations and not release configurations.

于 2013-04-26T23:23:25.067 回答