Click here to Skip to main content
14,829,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I debug my program. in fact, it is a source code and I set arguments for it. I have to write a application base on the source code. But when I debug it, a error message had occured:
"debug assertion fail..."
Please have me solve it.
Posted
Updated 15-Nov-10 5:54am
v2

Well, first thing I believe is that you are using MFC.

Most of the MFC's code has ASSERT macros that show this dialog box, when something is not proper. For example, you write a function StrLen, which accepts a character-pointer:
int StrLen(const char* pString)
{
  // Iterate through string to find length
  // and return length
}
what is caller makes a mistake like:

char* p = NULL;
StrLen(p);
In this case, your function would cause access violation. Well, you can use defensive programming using ASSERT as follows:
int StrLen(const char* pString)
{
  ASSERT(pString != NULL); // Must not be null
  // Iterate through string to find length
  // and return length
}

In this case, if null (not empty string) is passed, your StrLen is defensing against null pointer, and this would cause "Debug Assertion Failed" dialog box.

An MFC method, like SetWindowText, would most probably defense itself for two concerns: Ensure the CWnd* (the this pointer is value, AND the window itself is value window/control. It is achieved through:
ASSERT(this != NULL);
ASSERT(::IsWindow(m_hWnd));
and if any of assertion fails, you get that dialog box. Just click Retry and you will see a call stack. Find the bug and correct it!
   
v2
Comments
thienvan 17-Nov-10 2:35am
   
Thanks for your answer. I will try to bug it again...
Dalek Dave 17-Nov-10 3:40am
   
Good Answer!
   
Comments
thienvan 17-Nov-10 2:35am
   
Thanks...
Dalek Dave 17-Nov-10 3:40am
   
Good Link

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900