posix/except: add exception class for EAI_* codes

This commit is contained in:
Danny Robson 2017-12-22 18:34:00 +11:00
parent e437913746
commit d80855aedf
2 changed files with 52 additions and 1 deletions

View File

@ -97,3 +97,41 @@ error::throw_code (int code)
CHECK_NEQ (code, 0);
throw error (code);
}
///////////////////////////////////////////////////////////////////////////////
using util::posix::eai;
#include <netdb.h>
//-----------------------------------------------------------------------------
eai::eai (int code):
runtime_error (gai_strerror (code)),
m_code (code)
{ ; }
//-----------------------------------------------------------------------------
int
eai::code (void) const
{
return m_code;
}
//-----------------------------------------------------------------------------
void
eai::try_code (int code)
{
if (code)
throw_code (code);
}
//-----------------------------------------------------------------------------
void
eai::throw_code (int code)
{
throw eai { code };
}

View File

@ -50,6 +50,19 @@ namespace util::posix {
private:
int m_code;
};
}
class eai : public std::runtime_error {
public:
explicit eai (int code);
int code (void) const;
static void try_code (int);
static void throw_code [[gnu::noreturn]] (int);
private:
int m_code;
};
};
#endif