Skip to content
Snippets Groups Projects
Commit aa801e69 authored by jkaeber's avatar jkaeber
Browse files

Streamlined SystemException:

   - renamed "description()" member to "errorString()", 
   - renamed "where" attribute to "description", 
   - changed "what()" ouptut.
parent ffdfbcf6
No related branches found
No related tags found
No related merge requests found
...@@ -77,7 +77,7 @@ prefix_ void senf::UNSocketProtocol::check_and_unlink() ...@@ -77,7 +77,7 @@ prefix_ void senf::UNSocketProtocol::check_and_unlink()
::unlink(una.path().c_str()); ::unlink(una.path().c_str());
} }
catch (SystemException & e) { catch (SystemException & e) {
SENF_LOG(("UNSocketProtocol::check_and_unlink() failed; " << e.description() )); SENF_LOG(("UNSocketProtocol::check_and_unlink() failed; " << e.errorString() ));
} }
} }
......
...@@ -57,8 +57,8 @@ prefix_ senf::Daemon::~Daemon() ...@@ -57,8 +57,8 @@ prefix_ senf::Daemon::~Daemon()
if (! pidfile_.empty()) { if (! pidfile_.empty()) {
try { try {
LIBC_CALL( ::unlink, (pidfile_.c_str()) ); LIBC_CALL( ::unlink, (pidfile_.c_str()) );
} catch (SystemException e) { } catch (Exception e) {
e << "; could not unlink " << pidfile_.c_str(); // e << "; could not unlink " << pidfile_.c_str();
// throw; // throw;
} }
} }
...@@ -323,7 +323,7 @@ prefix_ bool senf::Daemon::pidfileCreate() ...@@ -323,7 +323,7 @@ prefix_ bool senf::Daemon::pidfileCreate()
// was some race condition, probably over NFS. // was some race condition, probably over NFS.
std::string tempname; 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]; char hostname[HOST_NAME_MAX+1];
......
...@@ -47,12 +47,11 @@ prefix_ char const * senf::Exception::what() ...@@ -47,12 +47,11 @@ prefix_ char const * senf::Exception::what()
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// senf::SystemException // 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; code_ = code;
if (! where.empty()) (*this) << "[" << errorString() << "]";
(*this) << where << ": "; if (! descr.empty()) (*this) << "; " << descr;
(*this) << "(" << code << ") " << description();
} }
///////////////////////////////cc.e//////////////////////////////////////// ///////////////////////////////cc.e////////////////////////////////////////
......
...@@ -35,9 +35,9 @@ prefix_ senf::Exception::Exception(std::string const & description) ...@@ -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) prefix_ senf::SystemException::SystemException(int code)
...@@ -45,9 +45,9 @@ prefix_ senf::SystemException::SystemException(int code) ...@@ -45,9 +45,9 @@ prefix_ senf::SystemException::SystemException(int code)
init("", 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() prefix_ int senf::SystemException::errorNumber()
...@@ -56,7 +56,7 @@ prefix_ int senf::SystemException::errorNumber() ...@@ -56,7 +56,7 @@ prefix_ int senf::SystemException::errorNumber()
return code_; return code_;
} }
prefix_ char const * senf::SystemException::description() prefix_ char const * senf::SystemException::errorString()
const const
{ {
return std::strerror(code_); return std::strerror(code_);
......
...@@ -152,9 +152,9 @@ namespace senf { ...@@ -152,9 +152,9 @@ namespace senf {
///\name Structors and default members ///\name Structors and default members
///@{ ///@{
explicit SystemException(std::string const & where = ""); explicit SystemException(std::string const & descr = "");
explicit SystemException(int code); explicit SystemException(int code);
SystemException(std::string const & where, int code); SystemException(std::string const & descr, int code);
virtual ~SystemException() throw(); virtual ~SystemException() throw();
...@@ -162,7 +162,7 @@ namespace senf { ...@@ -162,7 +162,7 @@ namespace senf {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
int errorNumber() const; ///< Error code (\c errno number) 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, 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); int c6=0, int c7=0, int c8=0, int c9=0);
...@@ -171,9 +171,10 @@ namespace senf { ...@@ -171,9 +171,10 @@ namespace senf {
private: private:
void init(std::string const & where, int code); void init(std::string const & descr, int code);
int code_; int code_;
std::string what_;
}; };
} }
......
...@@ -50,7 +50,8 @@ BOOST_AUTO_UNIT_TEST(errnoException) ...@@ -50,7 +50,8 @@ BOOST_AUTO_UNIT_TEST(errnoException)
} }
catch (senf::SystemException & e) { catch (senf::SystemException & e) {
BOOST_CHECK_EQUAL( e.errorNumber(), ENOENT ); 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" );
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment