天天看點

Try Catch

#pragma once
#include  <atlconv.h>

#define CatchErrorHandle(Content, Title, ErrorCode, Handle)\
try {\
	Content;\
}\
catch(const char* pszText)\
{\
	CString szTxt = CA2T(pszText);\
	::MessageBox(Handle, szTxt.GetBuffer(), Title, ErrorCode);\
}\
catch(const TCHAR* pszText)\
{\
	::MessageBox(Handle, pszText, Title, ErrorCode);\
}\
catch(CMemoryException *e)\
{\
	static TCHAR szError[512];\
	e->GetErrorMessage(szError, 512);\
	::MessageBox(Handle, szError, Title, ErrorCode);\
}\
catch(CFileException *e)\
{\
	static TCHAR szError[512];\
	e->GetErrorMessage(szError, 512);\
	::MessageBox(Handle, szError, Title, ErrorCode);\
}\
catch(CException *e)\
{\
	static TCHAR szError[512];\
	e->GetErrorMessage(szError, 512);\
	::MessageBox(Handle, szError, Title, ErrorCode);\
}

#define CatchErrorCode(Content, Title, ErrorCode) CatchErrorHandle(Content, Title, ErrorCode, NULL)

#define CatchError(Content) CatchErrorCode(Content, _T(“警告”), (MB_OK|MB_ICONWARNING))