3,881
社区成员
发帖
与我相关
我的任务
分享
/*
程序中需要调用其他库类的API,
但如果其他库类调用了类似 other_api()这样的函数,
难道自己的程序就只能等着挂掉么?
请教如何捕获这个异常!十分感谢...
*/
#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef map<int, string> its;
typedef its::iterator itsi;
#include <Windows.h>
void other_api();
int main(int argc, char* argv[])
{
//try // or __try
//{
// other_api();
//}
//catch (...) // or __except(EXCEPTION_EXECUTE_HANDLER)
//{
// cout << "catch here!" << endl;
//}
__try
{
other_api();
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
cout << "catch here!" << endl;
}
return 0;
}
void other_api()
{
its m;
m.clear();
itsi i = m.find(3);
cout << i->second << endl;
}
itsi i = m.find(3);
cout << i->second << endl;