winexception.cpp

来自「c+++ game uploading now」· C++ 代码 · 共 36 行

CPP
36
字号
/**
 @file
 Implements the Win::Exception class.
*/

#include "WinException.h"

using namespace Win;

char const Exception::msgFormat[]=
   "Problem: %s\noperating system tells us: %s";

void Exception::Show() const
{
    char *buf;
    char *sysMsg;

    ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
                    NULL,
                    _err,
                    MAKELANGID(LANG_NEUTRAL, 
                    SUBLANG_DEFAULT), // Default language
                    (LPTSTR) &sysMsg,
                    0,
                    NULL);

    //???BUG???: what if this is an "out of memory" exception?
    buf = new char[strlen (sysMsg) + strlen (_msg) + strlen (msgFormat) + 1];
    
    wsprintf(buf, msgFormat, _msg, sysMsg);
    ::MessageBox(0, buf, "Error", MB_ICONEXCLAMATION|MB_OK);

    // Free the buffer.
    ::LocalFree (sysMsg);
    delete buf;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?