errorhandling.cpp

来自「游戏音频程序设计-Beginning.Game.Audio.Programmin」· C++ 代码 · 共 48 行

CPP
48
字号
#include "ErrorHandling.h"

#include <sstream>

using namespace std;

namespace AudioEngine {

bool ThrowCError(HRESULT hr, std::string err, std::string filename, int line)
{
  CError e(hr, err, filename, line);

  string displaystr = e.GetMessageBoxString();
  displaystr += "Press ABORT to end the program, RETRY to debug, IGNORE to throw the error.";

  int result = MessageBox(NULL, displaystr.c_str(), "ErrorHandling.cpp", MB_ABORTRETRYIGNORE | MB_ICONSTOP);

  switch(result) {
    case IDABORT: // end the program immediately
      exit(-1); // could also use abort() here

    case IDRETRY: // break into the debugger
      return(false); // let the #define do this so we stop on the actual errant line

    case IDIGNORE: // continue as usual (throw the error)
      throw(e);
  }
  return(true); // just to avoid compiler warnings
}

string CError::GetMessageBoxString()
{
  stringstream str;

  str << "An error has occured in this program." << endl << endl <<
    "Error: " << GetError() << endl <<
    "File: " << GetFile() << endl <<
    "Line: " << GetLine() << endl;

  if (GetReason().size()) {
    str << "Reason: " << GetReason() << endl;
  }
  str << endl;

  return(str.str());
}

}; // namespace

⌨️ 快捷键说明

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