我一直在做一些实验,发现当整数被零除时,会抛出一个异常。
#include <iostream>
#include <stdexcept>
using namespace std;
int main
(
void
)
{
try
{
int x = 3;
int y = 0;
int z = x / y;
cout << "Didn't throw or signal" << endl;
}
catch (std::exception &e)
{
cout << "Caught exception " << e.what() << endl;
}
return 0;
}显然,它不会抛出std::异常。它还会抛出什么呢?
发布于 2009-12-16 04:06:10
这是一个Windows结构的异常,与C++无关-如果它是一个C程序,你会得到同样的异常。
发布于 2009-12-16 04:18:16
本文声称有一种方法可以使用_set_se_translator函数将结构化异常转换为C++异常。
http://www.codeproject.com/KB/cpp/seexception.aspx
发布于 2009-12-16 04:06:49
结果是未定义的,您可以使用__try / __except块来捕获错误(结构化异常处理)。但是,为什么不在划分之前简单地检查错误呢?
https://stackoverflow.com/questions/1909967
复制相似问题