errorhandling.h

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

H
64
字号
#ifndef ERRORHANDLING_H__INCLUDED
#define ERRORHANDLING_H__INCLUDED

#include <windows.h>
#include <string>

#include "dxerr8.h"

namespace AudioEngine {

extern bool ThrowCError(HRESULT hr, std::string err, std::string filename, int line);

#define ThrowIfFailed(result, err) { \
  if(FAILED(result)) { \
    if (!ThrowCError(result, err, __FILE__, __LINE__)) { \
      _asm { int 3 } \
    } \
  } \
} \

#define Throw(err) { \
  if (!ThrowCError(NULL, err, __FILE__, __LINE__)) { \
    _asm { int 3 } \
  } \
} \

class CError
{
public:

  CError(HRESULT hr, std::string err, std::string filename, int line) {
    SetFile(filename);
    SetError(err);
    SetLine(line);
    if (hr) SetReason(DXGetErrorString8(hr));
  }

  virtual ~CError() { }

  std::string GetFile() { return(m_File); }
  void SetFile(std::string f) { m_File = f; }
  
  std::string GetError() { return(m_Error); }
  void SetError(std::string f) { m_Error = f; }
  
  int GetLine() { return(m_Line); }
  void SetLine(int l) { m_Line = l; }
  
  std::string GetReason() { return(m_Reason); }
  void SetReason(std::string f) { m_Reason = f; }

  std::string GetMessageBoxString();

  
protected:              
  std::string m_File;
  int m_Line;
  std::string m_Error;
  std::string m_Reason;
};

} // namespace

#endif

⌨️ 快捷键说明

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