Variable/object validity check

Source: Internet
Author: User

 

 InGenerally, the ASSERT (x) macro is used to check the validity of variables in VC. The role of ASSERT is to check whether the expression is false or NULL. If the expression is false, an exception is thrown. In MFC, The ASSERT macro is widely used, for example:

BOOL CWnd: Attach (HWND hWndNew)
  
{
  
ASSERT (m_hWnd = NULL );// Only attach once, detach on
  
Destroy
  
//...
  
 
  
Return TRUE;
  
}
  
 
  
Void CString: AllocBuffer (int nLen)
  
{
  
ASSERT (nLen> = 0 );
  
ASSERT (nLen <= INT_MAX-1 );//
  
}
  
 
  
Void CDocument: AddView (CView * pView)
  
{
  
// Other code...
  
ASSERT (pView-> m_pDocument = NULL );
  
ASSERT (m_viewList.Find (pView, NULL) = NULL );
  
}
  

WhenWhen the ASSERT fails and an exception is thrown, a dialog box is displayed and the location where the ASSERT fails is reported. The error message is assertion failed in file <THIS_FILE> in line <__line __>.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.