Browse Source

2006-12-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	To know root cause of exception:
	
	* src/Exception.h
	(cause): New variable.
	(Exception): Added a parameter.
	(getMsg): Return const reference to msg.
	(getCause): New function.
	* src/DlRetryEx.h
	(DlRetryEx): Added a parameter 'cause'.
	Added an overloaded constructor.
	(DlAbortEx): Added a parameter 'cause'.
	Added an overloaded constructor.
	* src/SimpleLogger.cc
	(writeLog): Log nested exception messages recursively.
Tatsuhiro Tsujikawa 19 years ago
parent
commit
458cc27462
6 changed files with 46 additions and 6 deletions
  1. 17 0
      ChangeLog
  2. 1 0
      TODO
  3. 9 1
      src/DlAbortEx.h
  4. 9 1
      src/DlRetryEx.h
  5. 8 2
      src/Exception.h
  6. 2 2
      src/SimpleLogger.cc

+ 17 - 0
ChangeLog

@@ -1,3 +1,20 @@
+2006-12-01  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	To know root cause of exception:
+	
+	* src/Exception.h
+	(cause): New variable.
+	(Exception): Added a parameter.
+	(getMsg): Return const reference to msg.
+	(getCause): New function.
+	* src/DlRetryEx.h
+	(DlRetryEx): Added a parameter 'cause'.
+	Added an overloaded constructor.
+	(DlAbortEx): Added a parameter 'cause'.
+	Added an overloaded constructor.
+	* src/SimpleLogger.cc
+	(writeLog): Log nested exception messages recursively.
+
 2006-11-20  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	* src/DefaultBtProgressInfoFile.cc

+ 1 - 0
TODO

@@ -20,3 +20,4 @@
 * Add Turkish translation.
 * Add the message like "you can resume the transfer by invoking aria2 again" when the download stops.
 * Add --bt-timeout command line option.
+* Fix DefaultBtProgressInfoFile.cc: save(), load()

+ 9 - 1
src/DlAbortEx.h

@@ -38,13 +38,21 @@
 
 class DlAbortEx:public Exception {
 public:
-  DlAbortEx():Exception() {}
+  DlAbortEx(Exception* cause = 0):Exception(cause) {}
+
   DlAbortEx(const char* msg, ...):Exception() {
     va_list ap;
     va_start(ap, msg);
     setMsg(string(msg), ap);
     va_end(ap);
   }
+
+  DlAbortEx(Exception* cause, const char* msg, ...):Exception(cause) {
+    va_list ap;
+    va_start(ap, msg);
+    setMsg(string(msg), ap);
+    va_end(ap);
+  }
 };
 
 #endif // _D_DL_ABORT_EX_H_

+ 9 - 1
src/DlRetryEx.h

@@ -38,13 +38,21 @@
 
 class DlRetryEx:public Exception {
 public:
-  DlRetryEx():Exception() {}
+  DlRetryEx(Exception* cause = 0):Exception(cause) {}
+
   DlRetryEx(const char* msg, ...):Exception() {
     va_list ap;
     va_start(ap, msg);
     setMsg(msg, ap);
     va_end(ap);
   }
+
+  DlRetryEx(Exception* cause, const char* msg, ...):Exception(cause) {
+    va_list ap;
+    va_start(ap, msg);
+    setMsg(msg, ap);
+    va_end(ap);
+  }
 };
 
 #endif // _D_DL_RETRY_EX_H_

+ 8 - 2
src/Exception.h

@@ -46,15 +46,21 @@ class Exception {
 private:
   string msg;
 protected:
+  Exception* cause;
+
   void setMsg(const string& msgsrc, va_list ap) {
     char buf[256];
     vsnprintf(buf, sizeof(buf), msgsrc.c_str(), ap);
     msg = buf;
   }
 public:
-  Exception() {}
+  Exception(Exception* cause = 0):cause(cause) {}
+
   virtual ~Exception() {}
-  string getMsg() { return msg; }
+
+  const string& getMsg() const { return msg; }
+
+  Exception* getCause() const { return cause; }
 };
 
 #endif // _D_EXCEPTION_H_

+ 2 - 2
src/SimpleLogger.cc

@@ -110,9 +110,9 @@ void SimpleLogger::writeLog(FILE* file, int level, const char* msg, va_list ap,
   datestr[strlen(datestr)-1] = '\0';
   writeHeader(file, datestr, levelStr);
   vfprintf(file, string(Util::replace(msg, "\r", "")+"\n").c_str(), ap);
-  if(e != NULL) {
+  for(Exception* nestedEx = e; nestedEx; nestedEx = nestedEx->getCause()) {
     writeHeader(file, datestr, levelStr);
-    fprintf(file, "exception: %s\n", Util::replace(e->getMsg(), "\r", "").c_str());
+    fprintf(file, "exception: %s\n", Util::replace(nestedEx->getMsg(), "\r", "").c_str());
   }
   fflush(file);
 }