From: jkaeber Date: Thu, 6 Mar 2008 10:43:14 +0000 (+0000) Subject: Streamlined SystemException: X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=a66bffcc77f006b22190e1c27cbe0cd75fc4501c;p=senf.git Streamlined SystemException: - renamed "description()" member to "errorString()", - renamed "where" attribute to "description", - changed "what()" ouptut. git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@732 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Socket/Protocols/UN/UNSocketProtocol.cc b/Socket/Protocols/UN/UNSocketProtocol.cc index 61d1a71..0c58441 100644 --- a/Socket/Protocols/UN/UNSocketProtocol.cc +++ b/Socket/Protocols/UN/UNSocketProtocol.cc @@ -77,7 +77,7 @@ prefix_ void senf::UNSocketProtocol::check_and_unlink() ::unlink(una.path().c_str()); } catch (SystemException & e) { - SENF_LOG(("UNSocketProtocol::check_and_unlink() failed; " << e.description() )); + SENF_LOG(("UNSocketProtocol::check_and_unlink() failed; " << e.errorString() )); } } diff --git a/Utils/Daemon/Daemon.cc b/Utils/Daemon/Daemon.cc index 28d8a0c..1521867 100644 --- a/Utils/Daemon/Daemon.cc +++ b/Utils/Daemon/Daemon.cc @@ -57,8 +57,8 @@ prefix_ senf::Daemon::~Daemon() if (! pidfile_.empty()) { try { LIBC_CALL( ::unlink, (pidfile_.c_str()) ); - } catch (SystemException e) { - e << "; could not unlink " << pidfile_.c_str(); + } catch (Exception e) { + // e << "; could not unlink " << pidfile_.c_str(); // throw; } } @@ -323,7 +323,7 @@ prefix_ bool senf::Daemon::pidfileCreate() // was some race condition, probably over NFS. std::string tempname; - boost::format linkErrorFormat(" Could not link \"%1%\" to \"%2%\"."); + boost::format linkErrorFormat("; could not link \"%1%\" to \"%2%\"."); { char hostname[HOST_NAME_MAX+1]; diff --git a/Utils/Exception.cc b/Utils/Exception.cc index 28073e6..61d5860 100644 --- a/Utils/Exception.cc +++ b/Utils/Exception.cc @@ -47,12 +47,11 @@ prefix_ char const * senf::Exception::what() /////////////////////////////////////////////////////////////////////////// // senf::SystemException -prefix_ void senf::SystemException::init(std::string const & where, int code) +prefix_ void senf::SystemException::init(std::string const & descr, int code) { code_ = code; - if (! where.empty()) - (*this) << where << ": "; - (*this) << "(" << code << ") " << description(); + (*this) << "[" << errorString() << "]"; + if (! descr.empty()) (*this) << "; " << descr; } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Utils/Exception.cci b/Utils/Exception.cci index efe4961..f6d5a0a 100644 --- a/Utils/Exception.cci +++ b/Utils/Exception.cci @@ -35,9 +35,9 @@ prefix_ senf::Exception::Exception(std::string const & description) /////////////////////////////////////////////////////////////////////////// -prefix_ senf::SystemException::SystemException(std::string const & where) +prefix_ senf::SystemException::SystemException(std::string const & descr) { - init(where, errno); + init(descr, errno); } prefix_ senf::SystemException::SystemException(int code) @@ -45,9 +45,9 @@ prefix_ senf::SystemException::SystemException(int code) init("", code); } -prefix_ senf::SystemException::SystemException(std::string const & where, int code) +prefix_ senf::SystemException::SystemException(std::string const & descr, int code) { - init(where, code); + init(descr, code); } prefix_ int senf::SystemException::errorNumber() @@ -56,7 +56,7 @@ prefix_ int senf::SystemException::errorNumber() return code_; } -prefix_ char const * senf::SystemException::description() +prefix_ char const * senf::SystemException::errorString() const { return std::strerror(code_); diff --git a/Utils/Exception.hh b/Utils/Exception.hh index 7d56245..53d962f 100644 --- a/Utils/Exception.hh +++ b/Utils/Exception.hh @@ -152,9 +152,9 @@ namespace senf { ///\name Structors and default members ///@{ - explicit SystemException(std::string const & where = ""); + explicit SystemException(std::string const & descr = ""); explicit SystemException(int code); - SystemException(std::string const & where, int code); + SystemException(std::string const & descr, int code); virtual ~SystemException() throw(); @@ -162,7 +162,7 @@ namespace senf { /////////////////////////////////////////////////////////////////////////// int errorNumber() const; ///< Error code (\c errno number) - char const * description() const; ///< Error description (\c strerror() value) + char const * errorString() const; ///< Error string (\c strerror() value) bool anyOf(int c0, int c1=0, int c2=0, int c3=0, int c4=0, int c5=0, int c6=0, int c7=0, int c8=0, int c9=0); @@ -171,9 +171,10 @@ namespace senf { private: - void init(std::string const & where, int code); + void init(std::string const & descr, int code); int code_; + std::string what_; }; } diff --git a/Utils/Exception.test.cc b/Utils/Exception.test.cc index 5b2b95f..a65aa5f 100644 --- a/Utils/Exception.test.cc +++ b/Utils/Exception.test.cc @@ -50,7 +50,8 @@ BOOST_AUTO_UNIT_TEST(errnoException) } catch (senf::SystemException & e) { BOOST_CHECK_EQUAL( e.errorNumber(), ENOENT ); - BOOST_CHECK_EQUAL( e.what(), "::open(): (2) No such file or directory\nx=1\ny=2" ); + //BOOST_CHECK_EQUAL( e.what(), "::open(): (2) No such file or directory\nx=1\ny=2" ); + BOOST_CHECK_EQUAL( e.what(), "[No such file or directory]; ::open()\nx=1\ny=2" ); } }