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

#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 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值