forked from stuerp/foo_uie_webview
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExceptions.h
More file actions
31 lines (23 loc) · 1.14 KB
/
Exceptions.h
File metadata and controls
31 lines (23 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/** Exceptions.h: Copyright (c) P. Stuer **/
#pragma once
std::string GetErrorMessage(DWORD errorCode, const std::string& errorMessage) noexcept;
inline std::string GetErrorMessage(HRESULT hResult, const std::string& errorMessage) noexcept
{
return GetErrorMessage((DWORD)hResult, errorMessage);
}
#pragma warning(disable : 4820) // 'x' bytes padding added after data member 'y'
class ComponentException : public std::runtime_error
{
public:
ComponentException(const std::string& errorMessage) noexcept : std::runtime_error(errorMessage) {}
};
class Win32Exception : public std::runtime_error
{
public:
Win32Exception(const std::string& errorMessage) noexcept : Win32Exception(GetLastError(), errorMessage) {}
Win32Exception(DWORD errorCode, const std::string& errorMessage) noexcept : std::runtime_error(GetErrorMessage(errorCode, errorMessage)), _ErrorCode(errorCode) {}
Win32Exception(HRESULT hResult, const std::string& errorMessage) noexcept : std::runtime_error(GetErrorMessage((DWORD)hResult, errorMessage)), _ErrorCode((DWORD)hResult) {}
DWORD GetErrorCode() const { return _ErrorCode; }
private:
DWORD _ErrorCode;
};