summaryrefslogtreecommitdiff
path: root/src/AbstractCommand.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-04-27 02:22:14 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-04-27 02:22:14 +0000
commit1ef99931e131343f069a4b74edfc06196d72d85b (patch)
treed640f061a66a193d5f4d92b61836161208ccff14 /src/AbstractCommand.cc
parenta7952cce05a41c6e20d6eddc569a8bffe974aade (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/AbstractCommand.cc')
-rw-r--r--src/AbstractCommand.cc27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc
index 9745cf8a..40febf23 100644
--- a/src/AbstractCommand.cc
+++ b/src/AbstractCommand.cc
@@ -53,6 +53,7 @@
#include "Socket.h"
#include "message.h"
#include "prefs.h"
+#include "StringFormat.h"
namespace aria2 {
@@ -104,7 +105,7 @@ bool AbstractCommand::execute() {
if(!peerStat.isNull()) {
if(peerStat->getStatus() == PeerStat::REQUEST_IDLE) {
logger->info(MSG_ABORT_REQUESTED, cuid);
- onAbort(0);
+ onAbort();
req->resetUrl();
tryReserved();
return true;
@@ -141,39 +142,35 @@ bool AbstractCommand::execute() {
return executeInternal();
} else {
if(checkPoint.elapsed(timeout)) {
- throw new DlRetryEx(EX_TIME_OUT);
+ throw DlRetryEx(EX_TIME_OUT);
}
e->commands.push_back(this);
return false;
}
- } catch(DlAbortEx* err) {
+ } catch(DlAbortEx& err) {
logger->error(MSG_DOWNLOAD_ABORTED, err, cuid, req->getUrl().c_str());
- onAbort(err);
- delete(err);
+ onAbort();
req->resetUrl();
tryReserved();
return true;
- } catch(DlRetryEx* err) {
+ } catch(DlRetryEx& err) {
logger->info(MSG_RESTARTING_DOWNLOAD, err, cuid, req->getUrl().c_str());
req->addTryCount();
bool isAbort = e->option->getAsInt(PREF_MAX_TRIES) != 0 &&
req->getTryCount() >= (unsigned int)e->option->getAsInt(PREF_MAX_TRIES);
if(isAbort) {
- onAbort(err);
+ onAbort();
}
if(isAbort) {
logger->info(MSG_MAX_TRY, cuid, req->getTryCount());
logger->error(MSG_DOWNLOAD_ABORTED, err, cuid, req->getUrl().c_str());
- delete(err);
tryReserved();
return true;
} else {
- delete(err);
return prepareForRetry(e->option->getAsInt(PREF_RETRY_WAIT));
}
- } catch(DownloadFailureException* err) {
+ } catch(DownloadFailureException& err) {
logger->error(EX_EXCEPTION_CAUGHT, err);
- delete(err);
_requestGroup->setHaltRequested(true);
return true;
}
@@ -200,7 +197,7 @@ bool AbstractCommand::prepareForRetry(time_t wait) {
return true;
}
-void AbstractCommand::onAbort(Exception* ex) {
+void AbstractCommand::onAbort() {
logger->debug(MSG_UNREGISTER_CUID, cuid);
//_segmentMan->unregisterId(cuid);
if(!_requestGroup->getPieceStorage().isNull()) {
@@ -278,9 +275,9 @@ bool AbstractCommand::resolveHostname(const std::string& hostname,
return true;
break;
case NameResolver::STATUS_ERROR:
- throw new DlAbortEx(MSG_NAME_RESOLUTION_FAILED, cuid,
- hostname.c_str(),
- resolver->getError().c_str());
+ throw DlAbortEx(StringFormat(MSG_NAME_RESOLUTION_FAILED, cuid,
+ hostname.c_str(),
+ resolver->getError().c_str()).str());
default:
return false;
}