Skip to content

Commit

Permalink
Replace PrintException with PrintExceptionContinue + throw
Browse files Browse the repository at this point in the history
Just a pet peeve.

(PrintException has exactly the same body as PrintExceptionContinue but
does a re-throw at the end. Move these re-throws to the call
site, this aids understanding what is going on as well as eliminates a
bit of code duplication in util.cpp)
  • Loading branch information
laanwj committed Feb 26, 2014
1 parent 3480bf7 commit 4423571
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/rpcclient.cpp
Expand Up @@ -236,7 +236,8 @@ int CommandLineRPC(int argc, char *argv[])
nRet = abs(RPC_MISC_ERROR);
}
catch (...) {
PrintException(NULL, "CommandLineRPC()");
PrintExceptionContinue(NULL, "CommandLineRPC()");
throw;
}

if (strPrint != "")
Expand Down
9 changes: 0 additions & 9 deletions src/util.cpp
Expand Up @@ -948,15 +948,6 @@ void LogException(std::exception* pex, const char* pszThread)
LogPrintf("\n%s", message);
}

void PrintException(std::exception* pex, const char* pszThread)
{
std::string message = FormatException(pex, pszThread);
LogPrintf("\n\n************************\n%s\n", message);
fprintf(stderr, "\n\n************************\n%s\n", message.c_str());
strMiscWarning = message;
throw;
}

void PrintExceptionContinue(std::exception* pex, const char* pszThread)
{
std::string message = FormatException(pex, pszThread);
Expand Down
13 changes: 8 additions & 5 deletions src/util.h
Expand Up @@ -172,7 +172,6 @@ static inline bool error(const char* format)


void LogException(std::exception* pex, const char* pszThread);
void PrintException(std::exception* pex, const char* pszThread);
void PrintExceptionContinue(std::exception* pex, const char* pszThread);
void ParseString(const std::string& str, char c, std::vector<std::string>& v);
std::string FormatMoney(int64_t n, bool fPlus=false);
Expand Down Expand Up @@ -566,10 +565,12 @@ template <typename Callable> void LoopForever(const char* name, Callable func,
throw;
}
catch (std::exception& e) {
PrintException(&e, name);
PrintExceptionContinue(&e, name);
throw;
}
catch (...) {
PrintException(NULL, name);
PrintExceptionContinue(NULL, name);
throw;
}
}
// .. and a wrapper that just calls func once
Expand All @@ -589,10 +590,12 @@ template <typename Callable> void TraceThread(const char* name, Callable func)
throw;
}
catch (std::exception& e) {
PrintException(&e, name);
PrintExceptionContinue(&e, name);
throw;
}
catch (...) {
PrintException(NULL, name);
PrintExceptionContinue(NULL, name);
throw;
}
}

Expand Down

0 comments on commit 4423571

Please sign in to comment.