Skip to content

Instantly share code, notes, and snippets.

@willeccles
Last active December 15, 2021 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willeccles/9419ddf30ba8f3f4751f185c7ff8fc40 to your computer and use it in GitHub Desktop.
Save willeccles/9419ddf30ba8f3f4751f185c7ff8fc40 to your computer and use it in GitHub Desktop.
throw std::system_error with errno values quickly
#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