diff --git a/ChangeLog b/ChangeLog index ee8997b6..c7c5441a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-10-12 Tatsuhiro Tsujikawa + + Added errno member variable to Exception. + * src/DlAbortEx.cc + * src/DlAbortEx.h + * src/Exception.cc + * src/Exception.h + * src/RecoverableException.cc + * src/RecoverableException.h + 2010-10-12 Tatsuhiro Tsujikawa Simplified directory creation. diff --git a/src/DlAbortEx.cc b/src/DlAbortEx.cc index 2dd847f7..9a8dbb74 100644 --- a/src/DlAbortEx.cc +++ b/src/DlAbortEx.cc @@ -52,6 +52,10 @@ DlAbortEx::DlAbortEx(const char* file, int line, const std::string& msg, DlAbortEx::DlAbortEx(const char* file, int line, const RecoverableException& e): RecoverableException(file, line, e) {} +DlAbortEx::DlAbortEx +(const char* file, int line, int errnoArg, const std::string& msg): + RecoverableException(file, line, errnoArg, msg) {} + DlAbortEx::DlAbortEx(const char* file, int line, const std::string& msg, downloadresultcode::RESULT code): RecoverableException(file, line, msg, code) {} diff --git a/src/DlAbortEx.h b/src/DlAbortEx.h index 520ebecc..8445bb7d 100644 --- a/src/DlAbortEx.h +++ b/src/DlAbortEx.h @@ -49,6 +49,8 @@ public: DlAbortEx(const char* file, int line, const RecoverableException& e); + DlAbortEx(const char* file, int line, int errnoArg, const std::string& msg); + DlAbortEx(const char* file, int line, const std::string& msg, downloadresultcode::RESULT code); }; diff --git a/src/Exception.cc b/src/Exception.cc index f53c54b5..1e86b30b 100644 --- a/src/Exception.cc +++ b/src/Exception.cc @@ -39,27 +39,30 @@ namespace aria2 { Exception::Exception(const char* file, int line, const std::string& msg): - file_(file), line_(line), msg_(msg) {} + file_(file), line_(line), errno_(0), msg_(msg) {} Exception::Exception(const char* file, int line, const std::string& msg, const Exception& cause): - file_(file), line_(line), msg_(msg), cause_(cause.copy()) {} + file_(file), line_(line), errno_(0), msg_(msg), cause_(cause.copy()) {} Exception::Exception(const char* file, int line, const Exception& e): - file_(file), line_(line), msg_(e.msg_), cause_(e.cause_) + file_(file), line_(line), errno_(0), msg_(e.msg_), cause_(e.cause_) {} +Exception::Exception +(const char* file, int line, int errnoArg, const std::string& msg): + file_(file), line_(line), errno_(errnoArg), msg_(msg) {} + Exception::~Exception() throw() {} -const char* Exception::what() const throw() -{ - return msg_.c_str(); -} - -std::string Exception::stackTrace() const throw() +std::string Exception::stackTrace() const { std::stringstream s; - s << "Exception: " << "[" << file_ << ":" << line_ << "] " << what() << "\n"; + s << "Exception: " << "[" << file_ << ":" << line_ << "] "; + if(errno_) { + s << "errno=" << errno_ << " "; + } + s << what() << "\n"; SharedHandle e = cause_; while(!e.isNull()) { s << " -> " << "[" << e->file_ << ":" << e->line_ << "] " diff --git a/src/Exception.h b/src/Exception.h index 57ac633f..1002cfba 100644 --- a/src/Exception.h +++ b/src/Exception.h @@ -36,9 +36,12 @@ #define _D_EXCEPTION_H_ #include "common.h" -#include "SharedHandle.h" + +#include #include +#include "SharedHandle.h" + namespace aria2 { class Exception:public std::exception { @@ -47,6 +50,8 @@ private: int line_; + int errno_; + std::string msg_; SharedHandle cause_; @@ -62,11 +67,21 @@ public: Exception(const char* file, int line, const Exception& e); + Exception(const char* file, int line, int errnoArg, const std::string& msg); + virtual ~Exception() throw(); - virtual const char* what() const throw(); + virtual const char* what() const throw() + { + return msg_.c_str(); + } - std::string stackTrace() const throw(); + std::string stackTrace() const; + + int getErrno() const + { + return errno_; + } }; } // namespace aria2 diff --git a/src/RecoverableException.cc b/src/RecoverableException.cc index fd6f40b4..a0ba44a1 100644 --- a/src/RecoverableException.cc +++ b/src/RecoverableException.cc @@ -59,6 +59,11 @@ RecoverableException::RecoverableException Exception(file, line, e), code_(downloadresultcode::UNKNOWN_ERROR) {} +RecoverableException::RecoverableException +(const char* file, int line, int errnoArg, const std::string& msg): + Exception(file, line, errnoArg, msg), + code_(downloadresultcode::UNKNOWN_ERROR) {} + RecoverableException::RecoverableException (const char* file, int line, const std::string& msg, downloadresultcode::RESULT result): diff --git a/src/RecoverableException.h b/src/RecoverableException.h index 0b77074a..ccfc52ef 100644 --- a/src/RecoverableException.h +++ b/src/RecoverableException.h @@ -53,6 +53,9 @@ public: RecoverableException(const char* file, int line, const RecoverableException& e); + + RecoverableException + (const char* file, int line, int errnoArg, const std::string& msg); RecoverableException(const char* file, int line, const std::string& msg, downloadresultcode::RESULT result);