diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-10-20 03:20:49 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-10-20 03:20:49 +0300 |
commit | bd3116f43658fdd4ac145693e8ff4576061f22fa (patch) | |
tree | 93f0d7f0084a26b8db9de201323192a7711fbb0b /src/error.hpp | |
parent | code style & compiler warnings fixes (diff) | |
download | privilege-check-bd3116f43658fdd4ac145693e8ff4576061f22fa.tar.gz privilege-check-bd3116f43658fdd4ac145693e8ff4576061f22fa.zip |
refactoring
Diffstat (limited to 'src/error.hpp')
-rw-r--r-- | src/error.hpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/error.hpp b/src/error.hpp index b8ba468..40522bb 100644 --- a/src/error.hpp +++ b/src/error.hpp @@ -5,6 +5,8 @@ #pragma once +#include <Windows.h> + #include <exception> #include <system_error> @@ -12,11 +14,24 @@ typedef std::system_error Error; namespace error { - Error make(const char* function_name); + inline Error make(const char* function_name) + { + const auto ec = GetLastError(); + return {static_cast<int>(ec), std::system_category(), function_name}; + } - void raise(const char* function_name); + inline void raise(const char* function_name) + { + throw make(function_name); + } - void report(const std::exception&); + inline void report(const std::exception& e) + { + MessageBoxA(NULL, e.what(), NULL, MB_OK); + } - int get_code(const Error&); + inline int get_code(const Error& e) + { + return e.code().value(); + } } |