Windows 程式除錯心得01
最近看了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)