高分请教: 关于try...catch错误代码的定位 try...catch如何知道错误具体在哪行,错误信息具体是啥呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 具体在哪行?不太好明确的反应,错误信息GetLastError 可以加一个变量记录当前行号,在try块里面每行后面都把当前行号赋值给该变量,当进入catch块时判断这个变量记录的行号值 一般放try catch的地方都是自己认为会出现异常的地方,注意这个地方怎么确认就是凭经验了。 给你一个简单的例子#include <stdio.h>#include <string>#include <sstream>class _CMyExp{public: _CMyExp(const std::string &strErrorMsg, const char * szFileName, size_t nLine) { std::stringstream sTmp; sTmp << "ExpMsg:" << strErrorMsg << ". In File " << szFileName << " at Line " << nLine; m_strErrorMsg = sTmp.str(); }//private: std::string m_strErrorMsg;};#define CMyExp(x) _CMyExp(x, __FILE__, __LINE__)int main(int argc, char **argv){ try { if (9 == 9) { throw new CMyExp("uuu"); } } catch (_CMyExp *e) { ::printf("%s\r\n", e->m_strErrorMsg.c_str()); delete e; } return 0 ; } 用catch来扑捉相应的异常,然后用getlasterror来查看异常是什么 一个疑惑:在使用GetLastError()来检查错误时,感觉有时候并不一定就是目标模块产生的。不知道,是我理解错误还是? 哪位知道国内外大学中研究图像处理和识别,计算机视觉,机器视觉比较牛的,给我网址及其相关信息! 怎样获得视图类的句柄 _beginthreadex()问题。 VC中如何实现连接数码相机抓拍人像保存到数据中 如何在XP下用VC改计算机名 【Windows界面编程】界面编程,由此入门 -- 五大内容,绝对收获 急求:IGMP报文格式 outlook资源文件实现的问题? ATL COM对象多线程中的事件的激发?? 高分相送 用VC++实现循环写文件!(急) VC2005中头文件问题 关于httpwebrequest类的使用问题
#include <string>
#include <sstream>class _CMyExp
{
public:
_CMyExp(const std::string &strErrorMsg, const char * szFileName, size_t nLine)
{
std::stringstream sTmp; sTmp << "ExpMsg:" << strErrorMsg << ". In File " << szFileName << " at Line " << nLine; m_strErrorMsg = sTmp.str();
}
//private:
std::string m_strErrorMsg;
};#define CMyExp(x) _CMyExp(x, __FILE__, __LINE__)int main(int argc, char **argv)
{
try
{
if (9 == 9)
{
throw new CMyExp("uuu");
}
}
catch (_CMyExp *e)
{
::printf("%s\r\n", e->m_strErrorMsg.c_str());
delete e;
}
return 0 ;
}