diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-04-27 02:22:14 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-04-27 02:22:14 +0000 |
| commit | 1ef99931e131343f069a4b74edfc06196d72d85b (patch) | |
| tree | d640f061a66a193d5f4d92b61836161208ccff14 /src/Exception.cc | |
| parent | a7952cce05a41c6e20d6eddc569a8bffe974aade (diff) | |
2008-04-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten Exception class. Throw exception object, not its pointer and
catch by reference, so that remove problematic delete operator for
catched exception.
* src/Exception.cc
* src/Exception.h
* test/ExceptionTest.cc
* src/*: All files throwing/catching exception.
* test/*: All files throwing/catching exception.
Diffstat (limited to 'src/Exception.cc')
| -rw-r--r-- | src/Exception.cc | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/src/Exception.cc b/src/Exception.cc index 47beb3f5..6830d79f 100644 --- a/src/Exception.cc +++ b/src/Exception.cc @@ -33,17 +33,38 @@ */ /* copyright --> */ #include "Exception.h" -#include <ostream> namespace aria2 { -std::ostream& operator<<(std::ostream& o, const Exception& e) +Exception::Exception(const std::string& msg):exception(), _msg(msg) {} + +Exception::Exception(const std::string& msg, + const Exception& cause): + exception(), _msg(msg), _cause(cause.copy()) {} + +Exception::Exception(const Exception& e):_msg(e._msg), _cause(e._cause) +{} + +Exception::~Exception() throw() {} + +const char* Exception::what() const throw() +{ + return _msg.c_str(); +} + +std::string Exception::stackTrace() const throw() { - o << e.getMsg() << "\n"; - for(Exception* cause = e.getCause(); cause; cause = cause->getCause()) { - o << "Cause: " << cause->getMsg() << "\n"; + std::string stackTrace = "Exception: "; + stackTrace += what(); + stackTrace += "\n"; + SharedHandle<Exception> e = _cause; + while(!e.isNull()) { + stackTrace += " -> "; + stackTrace += e->what(); + stackTrace += "\n"; + e = e->_cause; } - return o; + return stackTrace; } } // namespace aria2 |
