except: style

This commit is contained in:
Danny Robson 2015-08-10 15:42:40 +10:00
parent 995f86b1f4
commit a8d341632e

View File

@ -21,10 +21,10 @@
#include <cstring> #include <cstring>
#include <cerrno> #include <cerrno>
using namespace std; using util::errno_error;
using namespace util;
///////////////////////////////////////////////////////////////////////////////
/// Construct an errno_error from a given error value. The error value MUST signal an error at /// Construct an errno_error from a given error value. The error value MUST signal an error at
/// construction time. /// construction time.
errno_error::errno_error (int _errno): errno_error::errno_error (int _errno):
@ -35,6 +35,7 @@ errno_error::errno_error (int _errno):
} }
///----------------------------------------------------------------------------
/// Construct an errno_error from the current value of errno. errno MUST signal an error at /// Construct an errno_error from the current value of errno. errno MUST signal an error at
/// construction time. /// construction time.
errno_error::errno_error (): errno_error::errno_error ():
@ -45,33 +46,48 @@ errno_error::errno_error ():
} }
///////////////////////////////////////////////////////////////////////////////
/// Throw an errno_error exception if errno currently signals an error. /// Throw an errno_error exception if errno currently signals an error.
void void
errno_error::try_code (void) errno_error::try_code (void)
{ try_code (errno); } {
try_code (errno);
}
///----------------------------------------------------------------------------
/// Throw an errno_error exception if 'code' represents an error. /// Throw an errno_error exception if 'code' represents an error.
void void
errno_error::try_code(int code) { errno_error::try_code (int code)
{
if (code != 0) if (code != 0)
throw errno_error(code); throw errno_error(code);
} }
///----------------------------------------------------------------------------
void void
errno_error::throw_code (void) errno_error::throw_code (void)
{ throw_code (errno); } {
throw_code (errno);
}
///----------------------------------------------------------------------------
void void
errno_error::throw_code (int code) { errno_error::throw_code (int code)
{
CHECK_NEQ (code, 0); CHECK_NEQ (code, 0);
throw errno_error (code); throw errno_error (code);
} }
///////////////////////////////////////////////////////////////////////////////
#if defined(PLATFORM_WIN32) #if defined(PLATFORM_WIN32)
using util::win32_error;
win32_error::win32_error (DWORD _id): win32_error::win32_error (DWORD _id):
runtime_error ("Win32 error"), runtime_error ("Win32 error"),
id (_id) id (_id)
@ -80,6 +96,7 @@ win32_error::win32_error (DWORD _id):
} }
//-----------------------------------------------------------------------------
win32_error::win32_error (void): win32_error::win32_error (void):
runtime_error ("Win32 error"), runtime_error ("Win32 error"),
id (GetLastError ()) id (GetLastError ())
@ -98,6 +115,7 @@ win32_error::try_code (void) {
} }
//-----------------------------------------------------------------------------
void void
win32_error::throw_code (void) { win32_error::throw_code (void) {
const auto id = GetLastError (); const auto id = GetLastError ();