C++ Client  0.0.0.0
C++ wrapper for Corelink DLL
CorelinkException.h
Go to the documentation of this file.
1 
5 #ifndef CORELINKEXCEPTION_H
6 #define CORELINKEXCEPTION_H
7 #pragma once
8 
9 #include "CorelinkClasses.h"
10 #include "CorelinkConst.h"
11 
12 namespace Corelink {
13 
14  inline CorelinkException::CorelinkException(const std::string& msg, const int& code) :
15  std::runtime_error(Corelink::Const::ErrorCodeString[code] + ": " + msg),
16  msg(msg), code(code)
17  {}
18 
19  inline void CorelinkException::GetDLLException(const unsigned int errorID) {
20  if (errorID == 0) { return; }
21  int errorLen;
22  char* errorMsg;
23  #ifdef WRAPPER_ALLOC
24  errorLen = CorelinkDLL::getErrorLen(errorID);
25  if (errorLen < 0) { throw Corelink::CorelinkException("No message remaining. Client closed", Corelink::Const::ERROR_CODE_NONE); }
26  errorMsg = new char[errorLen];
27  if (!CorelinkDLL::getErrorStr(errorID, errorMsg)) {
28  delete[] errorMsg;
29  throw Corelink::CorelinkException("No message remaining. Client closed", Corelink::Const::ERROR_CODE_NONE);
30  }
31  Corelink::CorelinkException exception(std::string(errorMsg, errorLen - 1), (int)errorMsg[errorLen - 1]);
32  delete[] errorMsg;
33  throw exception;
34  #else
35  errorMsg = CorelinkDLL::getError(errorID, errorLen);
36  if (errorLen == 0) { throw Corelink::CorelinkException("No message remaining. Client closed", Corelink::Const::ERROR_CODE_NONE); }
37  Corelink::CorelinkException exception = Corelink::CorelinkException(std::string(errorMsg, errorLen - 1), (int)errorMsg[errorLen - 1]);
38  CorelinkDLL::freeData(errorMsg);
39  throw exception;
40  #endif
41  }
42 
44 
45  inline CorelinkException::CorelinkException(const CorelinkException& rhs) :
46  std::runtime_error(Corelink::Const::ErrorCodeString[rhs.code] + ": " + rhs.msg),
47  msg(rhs.msg), code(rhs.code)
48  {}
49 }
50 
51 #endif