unsigned int __stdcall ThreadBase::ThreadRoutine( void* param ) { ThreadBase *pTB = (ThreadBase *)param; WDBG_THREADSTART(pTB->mName.c_str()); WTRACE("ThreadBase::ThreadRoutine"); // anything not caught in the derived thread will eventually end up here. // this is the bottom of our threads execution stack int aRet = 0; try { aRet = pTB->threadProcess(); } catch (WONCommon::WONException& ex) { WDBG_AH("WONException caught in ThreadRoutine!"); // set error code // WONException may set this to zero if undefined, so reset to -1 in that case pTB->mLastError = (ex.GetCode() != 0 ? ex.GetCode() : -1); ex.GetStream() << "Exception caught in Thread main. Thread terminated!"; // Set the exception event if needed if (pTB->hExceptionNotify) SetEvent(pTB->hExceptionNotify); aRet = pTB->mLastError; } #ifndef _NO_TOPLEVEL_CATCH catch (...) { WDBG_AH("Unhandled exception caught in ThreadRoutine!"); // Error code is unknown, set to (-1) if(! pTB->mLastError) pTB->mLastError = -1; // Log an error to event log WONCommon::EventLog aLog; aLog.Log("Unhandled Exception propogated to Thread main. Thread terminated!"); // Set the exception event if needed if (pTB->hExceptionNotify) SetEvent(pTB->hExceptionNotify); aRet = pTB->mLastError; } #endif WDBG_THREADSTOP; return aRet; }