在调用返回结构的函数后抛出异常时,堆栈展开过程失败
Stack unwind procedure failing when throwing exception after calling a function that returns a structure.
本周早些时候我已经发布了另外两个问题,关于异常以及为什么我的程序不处理异常。我已经从不必要的代码中"脱衣"了我的程序,下面是:
#include <string>
#include <stdexcept>
#include <iostream>
class some_class
{
public:
some_class(const some_class &);
some_class(const char *);
std::string m_id;
};
some_class::some_class(const char *p_id) :
m_id(p_id)
{
}
some_class::some_class(const some_class &p_that) :
m_id(p_that.m_id)
{
}
extern some_class return_a_struct(const char *p_id);
int run()
{
some_class l = return_a_struct("john");
throw std::runtime_error("something bad happened");
return 0;
}
extern "C" int main(int, char **)
{
try
{
run();
}
catch(const std::exception &p)
{
std::cout << p.what() << std::endl;
}
return 0;
}
some_class return_a_struct(const char *p_id)
{
return some_class(p_id);
}
输出应该是:somethingbad发生
根据我抛出的异常(std::runtime_error)。
在run()中,我调用返回some_class的函数。然后将返回的对象复制构造为我分配给它的对象。到目前为止,一切顺利。但是当我抛出异常时,程序就永远不会到达main函数中的catch处理程序。它崩溃时显示以下消息:
This application has requested the Runtime to terminate it in an unusual way
Please contact the application's support team for more information.
如果我提交对return_a_struct()的调用,则不会发生这种情况。
问题是:这是gcc (MinGW最新版本在Windows 7上运行的一部分)中的错误,还是我做错了什么?还有别的办法吗?
GCC-options:
gcc -fexceptions -g3 test_case.cpp -l libstdc++ -o test_case.exe
g++ test_case.cpp -o test_case.exe
相关文章:
- 运行时检查失败 #2 变量"A"周围的堆栈已损坏
- 运行时检查失败 #2 - 变量"e"周围的堆栈已损坏。发生
- 运行时检查失败 #2 - 变量周围的堆栈'...'已损坏
- 运行时检查失败 #2 - 变量"l1"周围的堆栈已损坏
- C++:此代码可以编译,但引发运行时检查失败 #2 - 围绕变量周围的堆栈'num'已损坏。发生
- 运行时检查失败 - 变量周围的堆栈已损坏
- 调试:运行时检查失败 #2 - 变量"LoggerThread"周围的堆栈已损坏
- 运行时检查失败 #2 - 变量周围的堆栈'k'已损坏
- 运行时检查失败 #2 - 变量"数字选择"周围的堆栈已损坏
- 运行时检查失败#2 - 变量周围的堆栈'myArray'已损坏.- 似乎无法弄清楚如何删除此错误
- 运行时检查失败 #2 - 变量周围的堆栈'normalIndex'已损坏
- 错误:运行时检查失败 #2 - 变量周围的堆栈已损坏
- 堆栈:C 失败中的平衡括号
- 运行时检查失败 #2 - 变量周围的堆栈'sample'已损坏
- 运行时检查失败 #2 - 变量周围的堆栈'ap'已损坏
- 使用链接列表实现堆栈,调试断言失败
- 运行时检查失败 #2 - 变量周围的堆栈---已损坏
- 运行时检查失败 #2 - 变量周围的堆栈'projectAverage'已损坏
- 运行时检查失败 #2 - 变量周围的堆栈'length'已损坏
- 在调试生成C++中获取调用堆栈失败