Skip to content

Commit 89802fe

Browse files
committed
Merge pull request #5438
27df412 make all catch() arguments const (Philip Kaufmann)
2 parents 851dfc7 + 27df412 commit 89802fe

24 files changed

+78
-82
lines changed

src/bitcoin-cli.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static bool AppInitRPC(int argc, char* argv[])
8686
}
8787
try {
8888
ReadConfigFile(mapArgs, mapMultiArgs);
89-
} catch(std::exception &e) {
89+
} catch (const std::exception& e) {
9090
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
9191
return false;
9292
}
@@ -206,18 +206,18 @@ int CommandLineRPC(int argc, char *argv[])
206206
// Connection succeeded, no need to retry.
207207
break;
208208
}
209-
catch (const CConnectionFailed& e) {
209+
catch (const CConnectionFailed&) {
210210
if (fWait)
211211
MilliSleep(1000);
212212
else
213213
throw;
214214
}
215215
} while (fWait);
216216
}
217-
catch (boost::thread_interrupted) {
217+
catch (const boost::thread_interrupted&) {
218218
throw;
219219
}
220-
catch (std::exception& e) {
220+
catch (const std::exception& e) {
221221
strPrint = string("error: ") + e.what();
222222
nRet = EXIT_FAILURE;
223223
}
@@ -240,7 +240,7 @@ int main(int argc, char* argv[])
240240
if(!AppInitRPC(argc, argv))
241241
return EXIT_FAILURE;
242242
}
243-
catch (std::exception& e) {
243+
catch (const std::exception& e) {
244244
PrintExceptionContinue(&e, "AppInitRPC()");
245245
return EXIT_FAILURE;
246246
} catch (...) {
@@ -252,7 +252,7 @@ int main(int argc, char* argv[])
252252
try {
253253
ret = CommandLineRPC(argc, argv);
254254
}
255-
catch (std::exception& e) {
255+
catch (const std::exception& e) {
256256
PrintExceptionContinue(&e, "CommandLineRPC()");
257257
} catch (...) {
258258
PrintExceptionContinue(NULL, "CommandLineRPC()");

src/bitcoin-tx.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,10 @@ static int CommandLineRawTx(int argc, char* argv[])
586586
OutputTx(tx);
587587
}
588588

589-
catch (boost::thread_interrupted) {
589+
catch (const boost::thread_interrupted&) {
590590
throw;
591591
}
592-
catch (std::exception& e) {
592+
catch (const std::exception& e) {
593593
strPrint = string("error: ") + e.what();
594594
nRet = EXIT_FAILURE;
595595
}
@@ -612,7 +612,7 @@ int main(int argc, char* argv[])
612612
if(!AppInitRawTx(argc, argv))
613613
return EXIT_FAILURE;
614614
}
615-
catch (std::exception& e) {
615+
catch (const std::exception& e) {
616616
PrintExceptionContinue(&e, "AppInitRawTx()");
617617
return EXIT_FAILURE;
618618
} catch (...) {
@@ -624,7 +624,7 @@ int main(int argc, char* argv[])
624624
try {
625625
ret = CommandLineRawTx(argc, argv);
626626
}
627-
catch (std::exception& e) {
627+
catch (const std::exception& e) {
628628
PrintExceptionContinue(&e, "CommandLineRawTx()");
629629
} catch (...) {
630630
PrintExceptionContinue(NULL, "CommandLineRawTx()");

src/bitcoind.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bool AppInit(int argc, char* argv[])
9797
try
9898
{
9999
ReadConfigFile(mapArgs, mapMultiArgs);
100-
} catch(std::exception &e) {
100+
} catch (const std::exception& e) {
101101
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
102102
return false;
103103
}
@@ -147,7 +147,7 @@ bool AppInit(int argc, char* argv[])
147147
detectShutdownThread = new boost::thread(boost::bind(&DetectShutdownThread, &threadGroup));
148148
fRet = AppInit2(threadGroup);
149149
}
150-
catch (std::exception& e) {
150+
catch (const std::exception& e) {
151151
PrintExceptionContinue(&e, "AppInit()");
152152
} catch (...) {
153153
PrintExceptionContinue(NULL, "AppInit()");

src/core_read.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx)
102102
try {
103103
ssData >> tx;
104104
}
105-
catch (const std::exception &) {
105+
catch (const std::exception&) {
106106
return false;
107107
}
108108

@@ -119,7 +119,7 @@ bool DecodeHexBlk(CBlock& block, const std::string& strHexBlk)
119119
try {
120120
ssBlock >> block;
121121
}
122-
catch (const std::exception &) {
122+
catch (const std::exception&) {
123123
return false;
124124
}
125125

src/init.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ bool AppInit2(boost::thread_group& threadGroup)
778778
try {
779779
boost::filesystem::rename(pathDatabase, pathDatabaseBak);
780780
LogPrintf("Moved old %s to %s. Retrying.\n", pathDatabase.string(), pathDatabaseBak.string());
781-
} catch(boost::filesystem::filesystem_error &error) {
781+
} catch (const boost::filesystem::filesystem_error&) {
782782
// failure is ok (well, not really, but it's not worse than what we started with)
783783
}
784784

@@ -931,7 +931,7 @@ bool AppInit2(boost::thread_group& threadGroup)
931931
filesystem::create_hard_link(source, dest);
932932
LogPrintf("Hardlinked %s -> %s\n", source.string(), dest.string());
933933
linked = true;
934-
} catch (filesystem::filesystem_error & e) {
934+
} catch (const filesystem::filesystem_error& e) {
935935
// Note: hardlink creation failing is not a disaster, it just means
936936
// blocks will get re-downloaded from peers.
937937
LogPrintf("Error hardlinking blk%04u.dat : %s\n", i, e.what());
@@ -1008,7 +1008,7 @@ bool AppInit2(boost::thread_group& threadGroup)
10081008
strLoadError = _("Corrupted block database detected");
10091009
break;
10101010
}
1011-
} catch(std::exception &e) {
1011+
} catch (const std::exception& e) {
10121012
if (fDebug) LogPrintf("%s\n", e.what());
10131013
strLoadError = _("Error opening block database");
10141014
break;

src/main.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
10911091
file >> header;
10921092
fseek(file.Get(), postx.nTxOffset, SEEK_CUR);
10931093
file >> txOut;
1094-
} catch (std::exception &e) {
1094+
} catch (const std::exception& e) {
10951095
return error("%s : Deserialize or I/O error - %s", __func__, e.what());
10961096
}
10971097
hashBlock = header.GetHash();
@@ -1174,7 +1174,7 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos)
11741174
try {
11751175
filein >> block;
11761176
}
1177-
catch (std::exception &e) {
1177+
catch (const std::exception& e) {
11781178
return error("%s : Deserialize or I/O error - %s", __func__, e.what());
11791179
}
11801180

@@ -2598,7 +2598,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
25982598
return state.Abort("Failed to write block");
25992599
if (!ReceivedBlockTransactions(block, state, pindex, blockPos))
26002600
return error("AcceptBlock() : ReceivedBlockTransactions failed");
2601-
} catch(std::runtime_error &e) {
2601+
} catch (const std::runtime_error& e) {
26022602
return state.Abort(std::string("System error: ") + e.what());
26032603
}
26042604

@@ -2990,7 +2990,7 @@ bool InitBlockIndex() {
29902990
return error("LoadBlockIndex() : genesis block cannot be activated");
29912991
// Force a chainstate write so that when we VerifyDB in a moment, it doesn't check stale data
29922992
return FlushStateToDisk(state, FLUSH_STATE_ALWAYS);
2993-
} catch(std::runtime_error &e) {
2993+
} catch (const std::runtime_error& e) {
29942994
return error("LoadBlockIndex() : failed to initialize block database: %s", e.what());
29952995
}
29962996
}
@@ -3030,7 +3030,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
30303030
blkdat >> nSize;
30313031
if (nSize < 80 || nSize > MAX_BLOCK_SIZE)
30323032
continue;
3033-
} catch (const std::exception &) {
3033+
} catch (const std::exception&) {
30343034
// no valid block header found; don't complain
30353035
break;
30363036
}
@@ -3090,11 +3090,11 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
30903090
mapBlocksUnknownParent.erase(it);
30913091
}
30923092
}
3093-
} catch (std::exception &e) {
3093+
} catch (const std::exception& e) {
30943094
LogPrintf("%s : Deserialize or I/O error - %s", __func__, e.what());
30953095
}
30963096
}
3097-
} catch(std::runtime_error &e) {
3097+
} catch (const std::runtime_error& e) {
30983098
AbortNode(std::string("System error: ") + e.what());
30993099
}
31003100
if (nLoaded > 0)
@@ -4088,7 +4088,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
40884088
ss << ": hash " << hash.ToString();
40894089
}
40904090
LogPrint("net", "Reject %s\n", SanitizeString(ss.str()));
4091-
} catch (std::ios_base::failure& e) {
4091+
} catch (const std::ios_base::failure&) {
40924092
// Avoid feedback loops by preventing reject messages from triggering a new reject message.
40934093
LogPrint("net", "Unparseable reject message received\n");
40944094
}
@@ -4192,7 +4192,7 @@ bool ProcessMessages(CNode* pfrom)
41924192
fRet = ProcessMessage(pfrom, strCommand, vRecv, msg.nTime);
41934193
boost::this_thread::interruption_point();
41944194
}
4195-
catch (std::ios_base::failure& e)
4195+
catch (const std::ios_base::failure& e)
41964196
{
41974197
pfrom->PushMessage("reject", strCommand, REJECT_MALFORMED, string("error parsing message"));
41984198
if (strstr(e.what(), "end of data"))
@@ -4210,10 +4210,10 @@ bool ProcessMessages(CNode* pfrom)
42104210
PrintExceptionContinue(&e, "ProcessMessages()");
42114211
}
42124212
}
4213-
catch (boost::thread_interrupted) {
4213+
catch (const boost::thread_interrupted&) {
42144214
throw;
42154215
}
4216-
catch (std::exception& e) {
4216+
catch (const std::exception& e) {
42174217
PrintExceptionContinue(&e, "ProcessMessages()");
42184218
} catch (...) {
42194219
PrintExceptionContinue(NULL, "ProcessMessages()");
@@ -4507,7 +4507,7 @@ bool CBlockUndo::ReadFromDisk(const CDiskBlockPos &pos, const uint256 &hashBlock
45074507
filein >> *this;
45084508
filein >> hashChecksum;
45094509
}
4510-
catch (std::exception &e) {
4510+
catch (const std::exception& e) {
45114511
return error("%s : Deserialize or I/O error - %s", __func__, e.what());
45124512
}
45134513

src/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ void static BitcoinMiner(CWallet *pwallet)
565565
}
566566
}
567567
}
568-
catch (boost::thread_interrupted)
568+
catch (const boost::thread_interrupted&)
569569
{
570570
LogPrintf("BitcoinMiner terminated\n");
571571
throw;

src/net.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ int CNetMessage::readHeader(const char *pch, unsigned int nBytes)
601601
try {
602602
hdrbuf >> hdr;
603603
}
604-
catch (const std::exception &) {
604+
catch (const std::exception&) {
605605
return -1;
606606
}
607607

@@ -1068,7 +1068,7 @@ void ThreadMapPort()
10681068
MilliSleep(20*60*1000); // Refresh every 20 minutes
10691069
}
10701070
}
1071-
catch (boost::thread_interrupted)
1071+
catch (const boost::thread_interrupted&)
10721072
{
10731073
r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0);
10741074
LogPrintf("UPNP_DeletePortMapping() returned : %d\n", r);
@@ -1854,7 +1854,7 @@ bool CAddrDB::Write(const CAddrMan& addr)
18541854
try {
18551855
fileout << ssPeers;
18561856
}
1857-
catch (std::exception &e) {
1857+
catch (const std::exception& e) {
18581858
return error("%s : Serialize or I/O error - %s", __func__, e.what());
18591859
}
18601860
FileCommit(fileout.Get());
@@ -1890,7 +1890,7 @@ bool CAddrDB::Read(CAddrMan& addr)
18901890
filein.read((char *)&vchData[0], dataSize);
18911891
filein >> hashIn;
18921892
}
1893-
catch (std::exception &e) {
1893+
catch (const std::exception& e) {
18941894
return error("%s : Deserialize or I/O error - %s", __func__, e.what());
18951895
}
18961896
filein.fclose();
@@ -1914,7 +1914,7 @@ bool CAddrDB::Read(CAddrMan& addr)
19141914
// de-serialize address data into one CAddrMan object
19151915
ssPeers >> addr;
19161916
}
1917-
catch (std::exception &e) {
1917+
catch (const std::exception& e) {
19181918
return error("%s : Deserialize or I/O error - %s", __func__, e.what());
19191919
}
19201920

src/qt/bitcoin.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public slots:
173173
boost::thread_group threadGroup;
174174

175175
/// Pass fatal exception message to UI thread
176-
void handleRunawayException(std::exception *e);
176+
void handleRunawayException(const std::exception *e);
177177
};
178178

179179
/** Main Bitcoin application object */
@@ -240,7 +240,7 @@ BitcoinCore::BitcoinCore():
240240
{
241241
}
242242

243-
void BitcoinCore::handleRunawayException(std::exception *e)
243+
void BitcoinCore::handleRunawayException(const std::exception *e)
244244
{
245245
PrintExceptionContinue(e, "Runaway exception");
246246
emit runawayException(QString::fromStdString(strMiscWarning));
@@ -260,7 +260,7 @@ void BitcoinCore::initialize()
260260
StartDummyRPCThread();
261261
}
262262
emit initializeResult(rv);
263-
} catch (std::exception& e) {
263+
} catch (const std::exception& e) {
264264
handleRunawayException(&e);
265265
} catch (...) {
266266
handleRunawayException(NULL);
@@ -277,7 +277,7 @@ void BitcoinCore::shutdown()
277277
Shutdown();
278278
qDebug() << __func__ << ": Shutdown finished";
279279
emit shutdownResult(1);
280-
} catch (std::exception& e) {
280+
} catch (const std::exception& e) {
281281
handleRunawayException(&e);
282282
} catch (...) {
283283
handleRunawayException(NULL);
@@ -551,7 +551,7 @@ int main(int argc, char *argv[])
551551
}
552552
try {
553553
ReadConfigFile(mapArgs, mapMultiArgs);
554-
} catch(std::exception &e) {
554+
} catch (const std::exception& e) {
555555
QMessageBox::critical(0, QObject::tr("Bitcoin Core"),
556556
QObject::tr("Error: Cannot parse configuration file: %1. Only use key=value syntax.").arg(e.what()));
557557
return false;
@@ -628,7 +628,7 @@ int main(int argc, char *argv[])
628628
app.exec();
629629
app.requestShutdown();
630630
app.exec();
631-
} catch (std::exception& e) {
631+
} catch (const std::exception& e) {
632632
PrintExceptionContinue(&e, "Runaway exception");
633633
app.handleRunawayException(QString::fromStdString(strMiscWarning));
634634
} catch (...) {

src/qt/intro.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void FreespaceChecker::check()
9595
replyMessage = tr("Path already exists, and is not a directory.");
9696
}
9797
}
98-
} catch(fs::filesystem_error &e)
98+
} catch (const fs::filesystem_error&)
9999
{
100100
/* Parent directory does not exist or is not accessible */
101101
replyStatus = ST_ERROR;
@@ -180,7 +180,7 @@ void Intro::pickDataDirectory()
180180
try {
181181
TryCreateDirectory(GUIUtil::qstringToBoostPath(dataDir));
182182
break;
183-
} catch(fs::filesystem_error &e) {
183+
} catch (const fs::filesystem_error&) {
184184
QMessageBox::critical(0, tr("Bitcoin Core"),
185185
tr("Error: Specified data directory \"%1\" cannot be created.").arg(dataDir));
186186
/* fall through, back to choosing screen */

0 commit comments

Comments
 (0)