(原)异常处理,调试辅助

    技术2022-05-11  142

    #define THROWEXCEPTION(STREXCEPTION) { / TCHAR sz[256] = {0} ;/ wsprintf(sz,"%s/n/n%s/n%u 行/nLastError : %u/n",/  STREXCEPTION,__FILE__,__LINE__,::GetLastError());/  throw YDebug::YException(sz); }

    #define DEBUGMSG(STRDEBUG) { / TCHAR sz[256] = {0} ;/ wsprintf(sz,"%s/n/n%s/n%u 行/nLastError : %u/n",/ STRDEBUG,__FILE__,__LINE__,::GetLastError());/ YDebug::DebugMsgBox(sz); 

    try  {   if (GetApp() == NULL)    THROWEXCEPTION(_T("YWnd::CreateEx 1 ")); 

      }

      catch (YDebug::YException &e) { e.MessageBox();  }  catch (...) {  DEBUGMSG(_T("CreateEx 1 未知错误")) }

    .h

    namespace YDebug{ /******************************************************* 模块名:  Exception 模块描述: 做成者: tsys2000@gmail.com 做成时间: 2005/11/ *******************************************************/ class YException { public:  YException (LPCTSTR msg) : m_msg(msg) {}   LPCTSTR GetMessage() const {return m_msg;}  void MessageBox(); private:  LPCTSTR m_msg; };

     template <typename Type>  void YsDebugHelper(LPCTSTR str,Type i) {  stringstream ss;  ss<<"ysay : "<<str<<"  $  "<< i << "  $"<<endl;  OutputDebugString(ss.str().c_str());  }

     void YsDebugHelper(LPCTSTR str);

     void DebugMsgBox(LPCTSTR str);

     void MsgBox(LPCTSTR str);

    }

    #ifdef _YSDEBUG#define YSTRACE(TYPE,Str,Data) YDebug::YsDebugHelper<TYPE>(Str,Data)#else#define YSTRACE(TYPE,Str,Data)#endif //

    #ifdef _YSDEBUG#define YSTRACE2(Str)   YDebug::YsDebugHelper(Str)#else#define YSTRACE2(Str)#endif //

    .cpp

    namespace YDebug{

     void YException::MessageBox() {#ifdef _YSDEBUG  ::MessageBox (0, GetMessage (),"YSay", MB_OK);#else  long t;  time(&t);  tm *_t = localtime(&t);  stringstream str;  str<<_t->tm_year<<"_"<<_t->tm_mon<<"_"<<_t->tm_mday<<".txt";    ofstream ss(str.str().c_str(),ios::app);   ss<<"-------------------------------"<<"/n";  ss<<GetMessage ()<<endl;  #endif } 

     void YsDebugHelper(LPCTSTR str) {  TCHAR buf [250];  ::wsprintf ((LPTSTR)buf, _T("YSay : %s/n"), str );  OutputDebugString(str);  }

     void DebugMsgBox(LPCTSTR str) {#if _DEBUG  ::MessageBox (0, (LPTSTR)str, _T("YS MsgBox"),  MB_OK);#endif } void MsgBox(LPCTSTR str) {  ::MessageBox (0, (LPTSTR)str, _T("YS MsgBox"),  MB_OK); }}

    转载请注明 tsys2000@gmail.com 


    最新回复(0)