try catch为什么没有捕获到除0异常

nostopping nostopping 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下:

#include "stdafx.h"
#include <exception>
#include <iostream>
using namespace std;

void Crash(void)
{
int i = 1;
int j = 0;

try
{
i /= j;
//cout << i << endl; //cout the value

}
catch(...)
{
cout << "Abnormal in Crash" << endl;
}
//cout << i << endl;

printf("No abnormal in Crash\n");
}

int _tmain(int argc, _TCHAR* argv[])
{
int i = 1;
int j = 0;

try
{
Crash();
}
catch(float i)
{
cout << "Error FLOAT:" << i << endl;
}
catch(int i)
{
cout << "Error INT:" << i << endl;
}
catch(...)
{
cout << "Abnormal in Main" << endl;
}

cout << "No Abnormal in Main" << endl;

getchar();
return 0;
}


问题是:
1.程序运行时为什么没有捕获到异常,输出为:
No abnormal in Crash
No Abnormal in Main
2.如果把Crash函数中注释掉的两个cout语句(或任意一个)打开,程序运行时系统会报出异常对话框,为何程序没有捕获到?
3.是不是每个异常都需要在程序中throw?
4.要捕获异常系统抛出的异常是否需要在编译器中设置什么选项(VS2008)?
...全文

相关推荐

评论 26
收藏 已收藏
分享
返回顶部
nostopping
C++ 语言 65,214 成员 250,514 内容