Bläddra i källkod

2010-10-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Added errno member variable to Exception.
	* src/DlAbortEx.cc
	* src/DlAbortEx.h
	* src/Exception.cc
	* src/Exception.h
	* src/RecoverableException.cc
	* src/RecoverableException.h
Tatsuhiro Tsujikawa 15 år sedan
förälder
incheckning
4ddc6eac58
7 ändrade filer med 55 tillägg och 13 borttagningar
  1. 10 0
      ChangeLog
  2. 4 0
      src/DlAbortEx.cc
  3. 2 0
      src/DlAbortEx.h
  4. 13 10
      src/Exception.cc
  5. 18 3
      src/Exception.h
  6. 5 0
      src/RecoverableException.cc
  7. 3 0
      src/RecoverableException.h

+ 10 - 0
ChangeLog

@@ -1,3 +1,13 @@
+2010-10-12  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	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  <t-tujikawa@users.sourceforge.net>
 
 	Simplified directory creation.

+ 4 - 0
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) {}

+ 2 - 0
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);
 };

+ 13 - 10
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() throw() {}
+Exception::Exception
+(const char* file, int line, int errnoArg, const std::string& msg):
+  file_(file), line_(line), errno_(errnoArg), msg_(msg) {}
 
-const char* Exception::what() const throw()
-{
-  return msg_.c_str();
-}
+Exception::~Exception() throw() {}
 
-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<Exception> e = cause_;
   while(!e.isNull()) {
     s << "  -> " << "[" << e->file_ << ":" << e->line_ << "] "

+ 18 - 3
src/Exception.h

@@ -36,9 +36,12 @@
 #define _D_EXCEPTION_H_
 
 #include "common.h"
-#include "SharedHandle.h"
+
+#include <cerrno>
 #include <string>
 
+#include "SharedHandle.h"
+
 namespace aria2 {
 
 class Exception:public std::exception {
@@ -47,6 +50,8 @@ private:
   
   int line_;
 
+  int errno_;
+
   std::string msg_;
 
   SharedHandle<Exception> 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;
 
-  std::string stackTrace() const throw();
+  int getErrno() const
+  {
+    return errno_;
+  }
 };
 
 } // namespace aria2

+ 5 - 0
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):

+ 3 - 0
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);