?
Solved

Debug Assertion Failure (daocore.cpp)

Posted on 1999-11-12
11
Medium Priority
?
813 Views
Last Modified: 2012-06-22
While exiting my application (exit(0)) I get this Assertion Failure. (I think) I closed all recordsets and the database. Could the problem have another origin than not closing the recordsets / database?

Here's the code where my application stops:
** daocore.cpp **
// ... you've not shut down with a call AfxDaoTerm()
ASSERT(m_pDAODBEngine == NULL);
**

Thanks.
0
Comment
Question by:Stapman
  • 6
  • 4
11 Comments
 
LVL 1

Accepted Solution

by:
abk102299 earned 200 total points
ID: 2203587
I don't think it's a good idea to exit MFC windows application with exit(0). In your case it seems the CWinApp::ExitInstance never been called. The data member m_lpfnDaoTerm of the CWinApp class usually stores the pointer to the AfxDaoTerm MFC's regular DAO termination function. That's where this assertion came from.

See MFC CWinApp::ExitInstance source code below:

int CWinApp::ExitInstance()
{
      // if we remember that we're unregistering,
      // don't save our profile settings

      if (m_pCmdInfo == NULL ||
            m_pCmdInfo->m_nShellCommand != CCommandLineInfo::AppUnregister)
      {
            if (!afxContextIsDLL)
                  SaveStdProfileSettings();
      }

      // Cleanup DAO if necessary
      if (m_lpfnDaoTerm != NULL)
      {
            // If a DLL, YOU must call AfxDaoTerm prior to ExitInstance
            ASSERT(!afxContextIsDLL);
            (*m_lpfnDaoTerm)();
      }

      return m_msgCur.wParam; // returns the value from PostQuitMessage
}
0
 
LVL 1

Expert Comment

by:abk102299
ID: 2203596
To close MFC windows application you ( for example ) can try to post the following message in the main frame window:

AfxGetMainWnd()->PostMessage(WM_COMMAND,ID_APP_EXIT);
0
 
LVL 22

Expert Comment

by:nietod
ID: 2203641
>> I don't think it's a good idea to exit MFC windows
>> application with exit(0)
Its not a good idea to exit ANY C++  application with exit()!.  Exit will not destroy local variables.  exit() is for extreme aborts, like error conditions.  but event then it should not be used.  You should throw an exception instead.  Basically, it should never be used.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 1

Expert Comment

by:abk102299
ID: 2203735
>> I don't think it's a good idea to exit MFC windows
>> application with exit(0)

> Its not a good idea to exit ANY C++
> application with exit()!.  Exit will
> not destroy local variables.  exit()
> is for extreme aborts, like error
> conditions.  

I would say there is abort() for extreme aborts. But it doesn't seem to be the case - it looks as regular exit with no error code (0). In this case I wouldn't throw exception - it's overreaction :)

> but event then it should
> not be used.  You should throw an
> exception instead. Basically, it
> should never be used.

Never say never...

0
 
LVL 22

Expert Comment

by:nietod
ID: 2203798
>> In this case I wouldn't throw exception
What case are you talking about?

>> Never say never...
I can't think of a reason to use it.  Can you?  You would have to justify failure to clean-up locals.  
0
 
LVL 1

Expert Comment

by:abk102299
ID: 2203918
>> In this case I wouldn't throw exception
> What case are you talking about?

exit(0);
//  ^^^  0 error code returned

>> Never say never...

> I can't think of a reason to use it. > Can you?  You would have to justify
> failure to clean-up locals

Sometimes it's OK. You can find a lot of routines where exit(ne_ret) is used in the main() function implementation. But in general you are right, of course.
0
 
LVL 1

Expert Comment

by:abk102299
ID: 2203949
Sorry, what I said is rather about return (ne_ret); Then NO, I don't have a reasonable example of the exit usage for now. Sometimes it's used in some temporary code - not for publishing, you know, but this is also doubtful practice.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2203997
exit(0);
//  ^^^  0 error code returned
Again you would be better of to throw an exception.  You can catch the exception in main and then use that to return the error code.  The exception object thrown can either be the error code or an object of a class that stores the error code.
0
 
LVL 1

Expert Comment

by:abk102299
ID: 2204070
Wouldn't it be a little inefficient sometimes to enclose a program by a try/catch construct without a special reason for doing this?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2204111
>> without a special reason for doing this?
Yes!  I'm not proposing this as a "normal" way to exit.  Only as an "extreme" exit when an error is detected.  Sort of like calling exit() deep within the program, but safer because locals are destroyed.  A program should end by returning from main() under ordinary conditions, or perhaps by throwing an uncaught exception, under extreme conditions.  Other forms of exit (exit(), abort() TerminateProcess()), are really suspect.
0
 

Author Comment

by:Stapman
ID: 2207634
Thanks!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question