From abce134089e980f6f19942117d98d64711637432 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 27 Apr 2016 16:07:42 +1000 Subject: [PATCH] except: add missing methods to win32_error --- except.cpp | 40 +++++++++++++++++++++++++++------------- except.hpp | 24 ++++++++++++++---------- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/except.cpp b/except.cpp index 1f17d3ac..446118e6 100644 --- a/except.cpp +++ b/except.cpp @@ -105,20 +105,34 @@ errno_error::throw_code (int code) using util::win32_error; -win32_error::win32_error (DWORD _id): - runtime_error ("Win32 error"), - id (_id) +//----------------------------------------------------------------------------- +win32_error::win32_error (DWORD _code): + runtime_error (code_string (_code)), + m_code (_code) { - CHECK_NEQ (id, (DWORD)ERROR_SUCCESS); + CHECK_NEQ (m_code, (DWORD)ERROR_SUCCESS); } //----------------------------------------------------------------------------- win32_error::win32_error (void): - runtime_error ("Win32 error"), - id (GetLastError ()) + win32_error (last_code ()) +{ ; } + + +/////////////////////////////////////////////////////////////////////////////// +DWORD +win32_error::code (void) const { - CHECK_NEQ (id, (DWORD)ERROR_SUCCESS); + return m_code; +} + + +//----------------------------------------------------------------------------- +DWORD +win32_error::last_code (void) +{ + return GetLastError (); } @@ -126,7 +140,7 @@ win32_error::win32_error (void): void win32_error::try_code (void) { - try_code (GetLastError ()); + try_code (last_code ()); } @@ -143,16 +157,16 @@ win32_error::try_code (DWORD id) void win32_error::throw_code (void) { - throw_code (GetLastError ()); + throw_code (last_code ()); } //----------------------------------------------------------------------------- void -win32_error::throw_code (DWORD id) +win32_error::throw_code (DWORD code) { - CHECK_NEQ (id, (DWORD)ERROR_SUCCESS); - throw win32_error (id); + CHECK_NEQ (code, (DWORD)ERROR_SUCCESS); + throw win32_error (code); } @@ -160,7 +174,7 @@ win32_error::throw_code (DWORD id) std::string win32_error::code_string (void) { - return code_string (GetLastError ()); + return code_string (last_code ()); } diff --git a/except.hpp b/except.hpp index 54cf2425..49b74aa3 100644 --- a/except.hpp +++ b/except.hpp @@ -72,20 +72,24 @@ namespace util { namespace util { class win32_error : public std::runtime_error { - public: - DWORD id; + public: + win32_error (DWORD _code); + win32_error (); - win32_error (DWORD _id); - win32_error (); + DWORD code (void) const; + static DWORD last_code (void); - static void try_code (void); - static void try_code (DWORD); + static void try_code (void); + static void try_code (DWORD); - static void throw_code [[gnu::noreturn]] (void); - static void throw_code [[gnu::noreturn]] (DWORD); + static void throw_code [[gnu::noreturn]] (void); + static void throw_code [[gnu::noreturn]] (DWORD); - static std::string code_string (void); - static std::string code_string (DWORD); + static std::string code_string (void); + static std::string code_string (DWORD); + + private: + DWORD m_code; }; } #endif