C++異常処理メカニズム----C++primer 4
1901 ワード
#include<iostream>
#include<stdexcept>
#include<exception>
using namespace std;
int main()
{
int a,b;
a=-3;
b=2;
try
{
if((a+b)<0)
throw runtime_error("have something wrong!!!");
cout<<a+b<<endl;
}
catch(runtime_error err )
{
cout<< err.what();
cout<<a<<' '<<b<<endl;
}
system("pause");
return 1;
}