except: add throw_code for win32_error

This commit is contained in:
Danny Robson 2015-08-10 15:42:58 +10:00
parent a8d341632e
commit fa9fac1d92
2 changed files with 29 additions and 9 deletions

View File

@ -105,20 +105,37 @@ win32_error::win32_error (void):
}
///////////////////////////////////////////////////////////////////////////////
void
win32_error::try_code (void) {
const auto id = GetLastError ();
if (id == ERROR_SUCCESS)
return;
throw win32_error (id);
win32_error::try_code (void)
{
try_code (GetLastError ());
}
//-----------------------------------------------------------------------------
void
win32_error::throw_code (void) {
const auto id = GetLastError ();
win32_error::try_code (DWORD id)
{
if (id == ERROR_SUCCESS)
return;
throw_code (id);
}
//-----------------------------------------------------------------------------
void
win32_error::throw_code (void)
{
throw_code (GetLastError ());
}
//-----------------------------------------------------------------------------
void
win32_error::throw_code (DWORD id)
{
CHECK (id != ERROR_SUCCESS);
throw win32_error (id);
}

View File

@ -74,7 +74,10 @@ namespace util {
win32_error ();
static void try_code (void);
static void throw_code (void);
static void try_code (DWORD);
static void throw_code [[gnu::noreturn]] (void);
static void throw_code [[gnu::noreturn]] (DWORD);
};
}
#endif