From 536f719c65eda67d5354e8b72d95fcd2e49b22d5 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Sun, 27 Feb 2011 00:03:17 +0100 Subject: [PATCH] exception class for c functions which set errno --- src/c++wrap.hh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/c++wrap.hh b/src/c++wrap.hh index 499ce1e8..ae6cc96f 100644 --- a/src/c++wrap.hh +++ b/src/c++wrap.hh @@ -24,8 +24,20 @@ #ifndef CPPWRAP_HH #define CPPWRAP_HH +#include #include std::string strerror_r(int errnum); +class errno_error: public std::runtime_error { + typedef std::runtime_error Base; + +public: + errno_error(const std::string &prefix, int err_ = errno) + : Base(prefix + ": " + strerror_r(err_)), err(err_) + {} + + const int err; +}; + #endif /* CPPWRAP_HH */