Last active
December 15, 2021 20:59
-
-
Save willeccles/9419ddf30ba8f3f4751f185c7ff8fc40 to your computer and use it in GitHub Desktop.
throw std::system_error with errno values quickly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef THROW_ERRNO_H | |
#define THROW_ERRNO_H | |
#include <cerrno> | |
#include <string> | |
#include <system_error> | |
[[noreturn]] | |
inline void throw_errno() { | |
throw std::system_error(errno, std::system_category()); | |
} | |
[[noreturn]] | |
inline void throw_errno(const std::string& msg) { | |
throw std::system_error(errno, std::system_category(), msg); | |
} | |
[[noreturn]] | |
inline void throw_errno(int ev) { | |
throw std::system_error(ev, std::system_category()); | |
} | |
[[noreturn]] | |
inline void throw_errno(int ev, const std::string& msg) { | |
throw std::system_error(ev, std::system_category(), msg); | |
} | |
#endif // THROW_ERRNO_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment