본문 바로가기

Game Programming

// definition of guard and unguard

728x90
반응형
// definition of guard and unguard
//
// guard/unguardf/unguard macros.
// For showing calling stack when errors occur in major functions.
// Meant to be enabled in release builds.
//
#if defined(_DEBUG) || !DO_GUARD
#define guard(func){static const TCHAR __FUNC_NAME__[]=TEXT(#func);
#define unguard}
#define unguardf(msg)}
#else
#if _MSC_VER
#define guard(func){static const TCHAR __FUNC_NAME__[]=TEXT(#func); try{
#define unguard}catch(TCHAR*Err){throw Err;}catch(...){appUnwindf(TEXT("%s"),__FUNC_NAME__); throw;}}
#define unguardf(msg)}catch(TCHAR*Err){throw Err;}catch(...){appUnwindf(TEXT("%s"),__FUNC_NAME__); appUnwindf msg; throw;}}
#else
#define guard(func){static const TCHAR __FUNC_NAME__[]=TEXT(#func); __Context __LOCAL_CONTEXT__; try{ if(setjmp(__Context::Env)) { throw 1; } else {
#define unguard}}catch(char*Err){throw Err;}catch(...) {appUnwindf(TEXT("%s"),__FUNC_NAME__); throw;}}
#define unguardf(msg)}}catch(char*Err){throw Err;}catch(...) {appUnwindf(TEXT("%s"),__FUNC_NAME__); appUnwindf msg; throw;}}
#endif
#endif
728x90
반응형