// dail_test.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include<vector>
#include<map>
#include<utility>
#include<string>
#include<bitset>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
try{
bitset<70> b1(ULLONG_MAX);
unsigned long test2 = b1.to_ulong();
}
catch(overflow_error &e)
{
cout<<e.what()<<endl;
}
try
{
throw runtime_error("test run time error");
}
catch(runtime_error &e1)
{
cout<<e1.what()<<endl;
}
return 0;
}
运行结果:
bitset<N> overflow
test run time error
==================================================================================================
C++程序运行时会抛出异常, 抛出第一个异常时,会搜索抛出此异常的函数。 如果没有找到匹配到的catch, 则终止此函数的执行, 并在调用此函数的函数中寻找catch. 如果仍然没有找到catch, 则该函数也被终止。 重复此过程,知道找到适当类型的catch. 如果不存在处理该异常的catch 子句,则通过terminate 函数终止程序运行。
更多关于编程语言, 数据库,算法等精品内容, 请访问 我的个人博客 huqijun.org
个人原创内容, 转载请注明来源!