// JP opened flex table

Click to See Complete Forum and Search --> : MFC new() doesnt throw Exception in 2nd thread


Mirko
June 2nd, 1998, 11:38 AM
Hi to All!


We have problem concerning operator new in MFC application: If we use it in the main thread it correctly throws exception CMemoryException (if not enough mem available). But if we use it in a secondary thread, it simply returns zero.


The second thread will be created inside a MFC DLL.


When trace step by step we see that a variable called m_pfnNewHandler should point to a function which would call AfxThrowMemoryException. But this pointer is zero or 0xFFFFFFFF.


Does anyone know this problem or any solution?

Thanx, Mirko

Petr Novotny
June 5th, 1998, 11:24 AM
Hi,


what call did you use to create a secondary thread?

Alexander Riesen
June 21st, 1998, 08:56 AM
The method to avoid the problem : using AfxBeginThread


This from afxmem.cpp:

_PNH AFXAPI AfxGetNewHandler(void)

{

AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();

return pState->m_pfnNewHandler;

}

and this means, that every thread has individual new-exceptions handler.

The problem is: "Why it wasn't initialized by MFC library per each thread ?"

I haven't found DLL_THREAD_ATTACH in MFC sources.


Good luck !

//JP added flex table