X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FException.cc;h=de36e8620af07d6054d0eae2bf68124151fda45d;hb=82ad2ed94c12c3e53097fef92978de8c28239fab;hp=80b6c98bd31068cd065dd4d4f65d63fa35092a02;hpb=145f6a7d0f3a6aaa77b3625351c952d24cb0b8a1;p=senf.git diff --git a/Utils/Exception.cc b/Utils/Exception.cc index 80b6c98..de36e86 100644 --- a/Utils/Exception.cc +++ b/Utils/Exception.cc @@ -39,16 +39,40 @@ prefix_ void senf::SystemException::init() // however all other solutions to format the message are terribly // ugly (since thay must use a static and shared buffer ...) std::stringstream s; - if (where) - s << where << ": "; - s << "(" << err << ") " << std::strerror(err); + if (where_) + s << where_ << ": "; + s << "(" << code_ << ") " << description(); buffer_ = s.str(); } -prefix_ char const * senf::SystemException::what() - const throw() +prefix_ void senf::throwErrno(char const * where, int code) { - return buffer_.c_str(); + switch (code) { + + // BOOST_PP_REPEAT is limited to 256 repetitions. The max errno value I found in any header file + // was somewhere around 530 or so. I assume going to 1024 will be good enough. This explicit + // code will be optimized into a jump table by g++ (which is more efficient than trying to do + // the table oneself) + +# define ExceptionCase(z, n, data) case n: throw ErrnoException(where); + BOOST_PP_REPEAT(256, ExceptionCase, _) ; +# undef ExceptionCase + +# define ExceptionCase(z, n, data) case 256+n: throw ErrnoException<256+n>(where); + BOOST_PP_REPEAT(256, ExceptionCase, _) ; +# undef ExceptionCase + +# define ExceptionCase(z, n, data) case 512+n: throw ErrnoException<512+n>(where); + BOOST_PP_REPEAT(256, ExceptionCase, _) ; +# undef ExceptionCase + +# define ExceptionCase(z, n, data) case 768+n: throw ErrnoException<768+n>(where); + BOOST_PP_REPEAT(256, ExceptionCase, _) ; +# undef ExceptionCase + + default: + throw SystemException(where, code); + } } ///////////////////////////////cc.e////////////////////////////////////////