Exception: tryRethrow() can be used to throw in all cases

It is useful to let tryRethrow be used in a mode where it never
returns. The PIM Manager will use that.
This commit is contained in:
Patrick Ohly 2013-02-06 10:57:02 +01:00
parent 771d630400
commit 501c32c06d
2 changed files with 10 additions and 3 deletions

View file

@ -882,7 +882,7 @@ SyncMLStatus Exception::handle(SyncMLStatus *status,
return status ? *status : new_status;
}
void Exception::tryRethrow(const std::string &explanation)
void Exception::tryRethrow(const std::string &explanation, bool mustThrow)
{
static const std::string statusre = ".* \\((?:local|remote), status (\\d+)\\)";
int status;
@ -902,6 +902,10 @@ void Exception::tryRethrow(const std::string &explanation)
SE_THROW_EXCEPTION_STATUS(StatusException, details, (SyncMLStatus)status);
}
}
if (mustThrow) {
throw std::runtime_error(explanation);
}
}
void Exception::tryRethrowDBus(const std::string &error)

View file

@ -534,9 +534,12 @@ class Exception : public std::runtime_error
/**
* Tries to identify exception class based on explanation string created by
* handle(). If successful, that exception is throw with the same
* attributes as in the original exception. Otherwise parse() returns.
* attributes as in the original exception.
*
* If not, tryRethrow() returns (mustThrow false) or throws a std::runtime_error
* with the explanation as text.
*/
static void tryRethrow(const std::string &explanation);
static void tryRethrow(const std::string &explanation, bool mustThrow = false);
/**
* Same as tryRethrow() for strings with a 'org.syncevolution.xxxx:' prefix,