except: add missing methods to win32_error

This commit is contained in:
Danny Robson 2016-04-27 16:07:42 +10:00
parent a941f4d74e
commit abce134089
2 changed files with 41 additions and 23 deletions

View File

@ -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 ());
}

View File

@ -73,11 +73,12 @@ namespace util {
namespace util {
class win32_error : public std::runtime_error {
public:
DWORD id;
win32_error (DWORD _id);
win32_error (DWORD _code);
win32_error ();
DWORD code (void) const;
static DWORD last_code (void);
static void try_code (void);
static void try_code (DWORD);
@ -86,6 +87,9 @@ namespace util {
static std::string code_string (void);
static std::string code_string (DWORD);
private:
DWORD m_code;
};
}
#endif