最近看了Everett N.McKay & Mike Woodring 的classical Debugging Windows Programs谈谈一些收获,以共大家分享. sharing with everybody
1.试着处理可能在程序里出错的构造函数.
Try to disposal construct function which was likely to slip a cog in a programme.
---------
CMyObject::CMyObject(const CString &resourse1,const CString &resourse2)
{
//Do safe initialization first
m_pRourse1=0;
m_pRourse2=0;
}
//now do initialization that can fail
try{
m_pRourse1=CreateResourse(resourse1);
m_pRourse2=CreateResourse(resourse2);
}
catch(...){
// must clean up here,since destructor won`t be called.
delete m_pResourse1;
delete m_pResourse2;
m_pResourse1=0;
m_pResourse2=0;
throw;
}
2.保证析构函数中的异常在析构函数内部得到处理.
Make sure the exception in destruct function be resolved in iteself.
---------
the same as the construct.(omit)