diff --git a/Socket/Protocols/UN/UNSocketProtocol.cc b/Socket/Protocols/UN/UNSocketProtocol.cc index 61d1a7194103788e0c0301105d413aeb27b4ce9a..0c58441f1bffff1f6c89dfd212bb2e3726300f5c 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 28d8a0c8437d6567eb79eb2f0a5e0673aac857a5..152186768576eec4327ae0403a2d17d48fdb47b4 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 28073e67e91a3704fdc941959adfda32676fc620..61d5860d8b624c3a4666c17738d9b86fcf6f9894 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 efe49618d6ec26100f7739dee85eb0ce4a63ea98..f6d5a0af8abbdef2e1143a250917da722dfe0df3 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 7d56245b964cb12b4e60f6722451a9340193e2e0..53d962f5e9897fbae5356420c971801125e65acc 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 5b2b95fa4049f4dcdda6113488dbea7dd219efac..a65aa5fd3af4e687e9a452f58b339d6a8cecf506 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" ); } }