posix/except: add templated error_code

This commit is contained in:
Danny Robson 2018-04-01 14:43:28 +10:00
parent cc54d23998
commit 5b9eae9b25
2 changed files with 10 additions and 2 deletions

View File

@ -29,7 +29,6 @@ using util::posix::error;
/// ///
/// The error value MUST be an error at construction time. /// The error value MUST be an error at construction time.
error::error (int _code): error::error (int _code):
std::runtime_error (::strerror (_code)),
m_code (_code) m_code (_code)
{ {
CHECK_NEQ (_code, 0); CHECK_NEQ (_code, 0);

View File

@ -25,7 +25,7 @@ namespace util::posix {
/// ///
/// Ideally this would be named `errno' but that symbol is permitted to /// Ideally this would be named `errno' but that symbol is permitted to
/// be a macro and significantly complicates symbol resolution either way. /// be a macro and significantly complicates symbol resolution either way.
class error : public std::runtime_error { class error : public std::exception {
public: public:
explicit error (int code); explicit error (int code);
error (); error ();
@ -52,6 +52,15 @@ namespace util::posix {
}; };
template <int CodeV>
struct error_code : public error {
error_code ():
error (CodeV)
{ ; }
};
class eai : public std::runtime_error { class eai : public std::runtime_error {
public: public:
explicit eai (int code); explicit eai (int code);