GOG GALAXY SDK Documentation
GalaxyExceptionHelper.h
1 #ifndef GALAXY_EXCEPTION_HELPER_H
2 #define GALAXY_EXCEPTION_HELPER_H
3 
4 #include "Errors.h"
5 #include <string>
6 
7 namespace galaxy
8 {
9  namespace api
10  {
11  namespace details
12  {
13 
14 #define GALAXY_EXCEPTION_HELPER_ERROR_CLASS(Exception, ExceptionInterface, ErrorType) \
15 class Exception : public ExceptionInterface \
16 {\
17 public: \
18  explicit Exception(const IError* exception) : message(exception->GetMsg()) {}\
19  virtual const char* GetName() const { return #ExceptionInterface; } \
20  virtual const char* GetMsg() const { return message.c_str(); } \
21  virtual api::IError::Type GetType() const { return ErrorType; } \
22 \
23 private: \
24  const std::string message; \
25 }
26 
27  GALAXY_EXCEPTION_HELPER_ERROR_CLASS(UnauthorizedAccessError, IUnauthorizedAccessError, IError::UNAUTHORIZED_ACCESS);
28  GALAXY_EXCEPTION_HELPER_ERROR_CLASS(InvalidArgumentError, IInvalidArgumentError, IError::INVALID_ARGUMENT);
29  GALAXY_EXCEPTION_HELPER_ERROR_CLASS(InvalidStateError, IInvalidStateError, IError::INVALID_STATE);
30  GALAXY_EXCEPTION_HELPER_ERROR_CLASS(RuntimeError, IRuntimeError, IError::RUNTIME_ERROR);
31 
32  }
33 
34  inline void ThrowIfGalaxyError()
35  {
36  const IError* error = GetError();
37  if (error)
38  {
39  switch (error->GetType())
40  {
41  case IError::UNAUTHORIZED_ACCESS: throw details::UnauthorizedAccessError(error);
42  case IError::INVALID_ARGUMENT: throw details::InvalidArgumentError(error);
43  case IError::INVALID_STATE: throw details::InvalidStateError(error);
44  default: throw details::RuntimeError(error);
45  }
46  }
47  }
48 
49  }
50 }
51 
52 #endif
Contains classes representing exceptions.
GALAXY_DLL_EXPORT const IError *GALAXY_CALLTYPE GetError()
Retrieves error connected with the last API call on the local thread.