Skip to content

Commit 0a665de

Browse files
committed
use a const reference when catching exceptions
1 parent b5b758b commit 0a665de

14 files changed

+59
-59
lines changed

src/app/BlockCompressor.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -682,14 +682,14 @@ T FileCompressTask<T>::run()
682682
for (uint i = 0; i < _listeners.size(); i++)
683683
_cos->addListener(*_listeners[i]);
684684
}
685-
catch (invalid_argument& e) {
685+
catch (const invalid_argument& e) {
686686
CLEANUP_COMP_OS
687687
stringstream sserr;
688688
sserr << "Cannot create compressed stream: " << e.what();
689689
return T(Error::ERR_CREATE_COMPRESSOR, 0, 0, sserr.str().c_str());
690690
}
691691
}
692-
catch (exception& e) {
692+
catch (const exception& e) {
693693
CLEANUP_COMP_OS
694694
stringstream sserr;
695695
sserr << "Cannot open output file '" << outputName << "' for writing: " << e.what();
@@ -723,7 +723,7 @@ T FileCompressTask<T>::run()
723723
_is = ifs;
724724
}
725725
}
726-
catch (exception& e) {
726+
catch (const exception& e) {
727727
CLEANUP_COMP_IS
728728
CLEANUP_COMP_OS
729729
delete _cos;
@@ -757,7 +757,7 @@ T FileCompressTask<T>::run()
757757
_is->read(reinterpret_cast<char*>(&sa._array[0]), sa._length);
758758
len = *_is ? sa._length : int(_is->gcount());
759759
}
760-
catch (exception& e) {
760+
catch (const exception& e) {
761761
CLEANUP_COMP_IS
762762
CLEANUP_COMP_OS
763763
const uint64 w = _cos->getWritten();
@@ -778,7 +778,7 @@ T FileCompressTask<T>::run()
778778
_cos->write(reinterpret_cast<const char*>(&sa._array[0]), len);
779779
}
780780
}
781-
catch (IOException& ioe) {
781+
catch (const IOException& ioe) {
782782
CLEANUP_COMP_IS
783783
CLEANUP_COMP_OS
784784
const uint64 w = _cos->getWritten();
@@ -787,7 +787,7 @@ T FileCompressTask<T>::run()
787787
_cos = nullptr;
788788
return T(ioe.error(), read, w, ioe.what());
789789
}
790-
catch (exception& e) {
790+
catch (const exception& e) {
791791
CLEANUP_COMP_IS
792792
CLEANUP_COMP_OS
793793
const uint64 w = _cos->getWritten();
@@ -817,7 +817,7 @@ T FileCompressTask<T>::run()
817817
CLEANUP_COMP_IS
818818
_is = nullptr;
819819
}
820-
catch (exception&) {
820+
catch (const exception&) {
821821
// Ignore: best effort
822822
}
823823

@@ -917,7 +917,7 @@ FileCompressTask<T>::~FileCompressTask()
917917

918918
_is = nullptr;
919919
}
920-
catch (exception&) {
920+
catch (const exception&) {
921921
// Ignore: best effort
922922
}
923923
}
@@ -931,7 +931,7 @@ void FileCompressTask<T>::dispose()
931931
_cos->close();
932932
}
933933
}
934-
catch (exception& e) {
934+
catch (const exception& e) {
935935
cerr << "Compression failure: " << e.what() << endl;
936936
exit(Error::ERR_WRITE_FILE);
937937
}

src/app/BlockDecompressor.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ FileDecompressTask<T>::~FileDecompressTask()
442442

443443
_os = nullptr;
444444
}
445-
catch (exception&) {
445+
catch (const exception&) {
446446
// Ignore: best effort
447447
}
448448
}
@@ -564,7 +564,7 @@ T FileDecompressTask<T>::run()
564564

565565
_os = ofs;
566566
}
567-
catch (exception& e) {
567+
catch (const exception& e) {
568568
stringstream sserr;
569569
sserr << "Cannot open output file '" << outputName << "' for writing: " << e.what();
570570
return T(Error::ERR_CREATE_FILE, 0, sserr.str().c_str());
@@ -605,15 +605,15 @@ T FileDecompressTask<T>::run()
605605
for (uint i = 0; i < _listeners.size(); i++)
606606
_cis->addListener(*_listeners[i]);
607607
}
608-
catch (invalid_argument& e) {
608+
catch (const invalid_argument& e) {
609609
CLEANUP_DECOMP_IS
610610
CLEANUP_DECOMP_OS
611611
stringstream sserr;
612612
sserr << "Cannot create compressed stream: " << e.what();
613613
return T(Error::ERR_CREATE_DECOMPRESSOR, 0, sserr.str().c_str());
614614
}
615615
}
616-
catch (exception& e) {
616+
catch (const exception& e) {
617617
CLEANUP_DECOMP_IS
618618
CLEANUP_DECOMP_OS
619619
stringstream sserr;
@@ -653,7 +653,7 @@ T FileDecompressTask<T>::run()
653653
read += decoded;
654654
}
655655
}
656-
catch (exception& e) {
656+
catch (const exception& e) {
657657
dispose();
658658
const uint64 d = _cis->getRead();
659659
CLEANUP_DECOMP_IS
@@ -667,7 +667,7 @@ T FileDecompressTask<T>::run()
667667
}
668668
} while (_cis->eof() == 0);
669669
}
670-
catch (IOException& e) {
670+
catch (const IOException& e) {
671671
dispose();
672672
const uint64 d = _cis->getRead();
673673
bool isEOF = _cis->eof();
@@ -684,7 +684,7 @@ T FileDecompressTask<T>::run()
684684
sserr << e.what();
685685
return T(e.error(), d, sserr.str().c_str());
686686
}
687-
catch (exception& e) {
687+
catch (const exception& e) {
688688
dispose();
689689
const uint64 d = _cis->getRead();
690690
bool isEOF = _cis->eof();
@@ -720,7 +720,7 @@ T FileDecompressTask<T>::run()
720720
CLEANUP_DECOMP_OS
721721
_os = nullptr;
722722
}
723-
catch (exception&) {
723+
catch (const exception&) {
724724
// Ignore: best effort
725725
}
726726

@@ -815,7 +815,7 @@ void FileDecompressTask<T>::dispose()
815815
_cis->close();
816816
}
817817
}
818-
catch (exception& e) {
818+
catch (const exception& e) {
819819
cerr << "Decompression failure: " << e.what() << endl;
820820
exit(Error::ERR_WRITE_FILE);
821821
}

src/app/Kanzi.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ int main(int argc, const char* argv[])
11281128
int code = bc.compress(written);
11291129
return code;
11301130
}
1131-
catch (exception& e) {
1131+
catch (const exception& e) {
11321132
cerr << "Could not create the compressor: " << e.what() << endl;
11331133
return Error::ERR_CREATE_COMPRESSOR;
11341134
}
@@ -1141,7 +1141,7 @@ int main(int argc, const char* argv[])
11411141
int code = bd.decompress(read);
11421142
return code;
11431143
}
1144-
catch (exception& e) {
1144+
catch (const exception& e) {
11451145
cerr << "Could not create the decompressor: " << e.what() << endl;
11461146
return Error::ERR_CREATE_DECOMPRESSOR;
11471147
}
@@ -1150,12 +1150,12 @@ int main(int argc, const char* argv[])
11501150
cout << "Missing arguments: try --help or -h" << endl;
11511151
return Error::ERR_MISSING_PARAM;
11521152
}
1153-
catch (invalid_argument& e) {
1153+
catch (const invalid_argument& e) {
11541154
// May be thrown by ThreadPool
11551155
cerr << e.what() << endl;
11561156
return Error::ERR_INVALID_PARAM;
11571157
}
1158-
catch (runtime_error& e) {
1158+
catch (const runtime_error& e) {
11591159
// May be thrown by ThreadPool
11601160
cerr << e.what() << endl;
11611161
return Error::ERR_INVALID_PARAM;

src/bitstream/DefaultInputBitStream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ int DefaultInputBitStream::readFromInputStream(uint count)
189189
// Clear flags (required for future seeks when EOF is reached)
190190
_is.clear();
191191
}
192-
catch (runtime_error& e) {
192+
catch (const runtime_error& e) {
193193
// Catch IOException without depending on io package
194194
throw BitStreamException(e.what(), BitStreamException::INPUT_OUTPUT);
195195
}
@@ -215,7 +215,7 @@ bool DefaultInputBitStream::hasMoreToRead()
215215
try {
216216
readFromInputStream(_bufferSize);
217217
}
218-
catch (BitStreamException&) {
218+
catch (const BitStreamException&) {
219219
return false;
220220
}
221221

src/bitstream/DefaultOutputBitStream.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void DefaultOutputBitStream::_close()
150150
_availBits = 64;
151151
flush();
152152
}
153-
catch (BitStreamException&) {
153+
catch (const BitStreamException&) {
154154
// Revert fields to allow subsequent attempts in case of transient failure
155155
_position = savedPosition;
156156
_availBits = savedBitIndex;
@@ -164,7 +164,7 @@ void DefaultOutputBitStream::_close()
164164
if (_os.bad())
165165
throw BitStreamException("Write to bitstream failed.", BitStreamException::INPUT_OUTPUT);
166166
}
167-
catch (ios_base::failure& e) {
167+
catch (const ios_base::failure& e) {
168168
throw BitStreamException(e.what(), BitStreamException::INPUT_OUTPUT);
169169
}
170170

@@ -198,7 +198,7 @@ void DefaultOutputBitStream::flush()
198198
_position = 0;
199199
}
200200
}
201-
catch (ios_base::failure& e) {
201+
catch (const ios_base::failure& e) {
202202
throw BitStreamException(e.what(), BitStreamException::INPUT_OUTPUT);
203203
}
204204
}
@@ -208,7 +208,7 @@ DefaultOutputBitStream::~DefaultOutputBitStream()
208208
try {
209209
_close();
210210
}
211-
catch (exception&) {
211+
catch (const exception&) {
212212
// Ignore and continue
213213
}
214214

src/io/CompressedInputStream.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ CompressedInputStream::~CompressedInputStream()
226226
try {
227227
close();
228228
}
229-
catch (exception&) {
229+
catch (const exception&) {
230230
// Ignore and continue
231231
}
232232

@@ -302,7 +302,7 @@ void CompressedInputStream::readHeader()
302302
_entropyType = short(_ibs->readBits(5));
303303
_ctx.putString("entropy", EntropyDecoderFactory::getName(_entropyType));
304304
}
305-
catch (invalid_argument&) {
305+
catch (const invalid_argument&) {
306306
stringstream err;
307307
err << "Invalid bitstream, unknown entropy type: " << _entropyType;
308308
throw IOException(err.str(), Error::ERR_INVALID_CODEC);
@@ -313,7 +313,7 @@ void CompressedInputStream::readHeader()
313313
_transformType = _ibs->readBits(48);
314314
_ctx.putString("transform", TransformFactory<byte>::getName(_transformType));
315315
}
316-
catch (invalid_argument&) {
316+
catch (const invalid_argument&) {
317317
stringstream err;
318318
err << "Invalid bitstream, unknown transform type: " << _transformType;
319319
throw IOException(err.str(), Error::ERR_INVALID_CODEC);
@@ -453,11 +453,11 @@ int CompressedInputStream::_get(int inc)
453453

454454
return res;
455455
}
456-
catch (IOException&) {
456+
catch (const IOException&) {
457457
setstate(ios::badbit);
458458
throw; // rethrow
459459
}
460-
catch (exception&) {
460+
catch (const exception&) {
461461
setstate(ios::badbit);
462462
throw; // rethrow
463463
}
@@ -694,14 +694,14 @@ int64 CompressedInputStream::processBlock()
694694

695695
return decoded;
696696
}
697-
catch (IOException&) {
697+
catch (const IOException&) {
698698
for (vector<DecodingTask<DecodingTaskResult>*>::iterator it = tasks.begin(); it != tasks.end(); ++it)
699699
delete *it;
700700

701701
tasks.clear();
702702
throw;
703703
}
704-
catch (exception& e) {
704+
catch (const exception& e) {
705705
for (vector<DecodingTask<DecodingTaskResult>*>::iterator it = tasks.begin(); it != tasks.end(); ++it)
706706
delete *it;
707707

@@ -718,7 +718,7 @@ void CompressedInputStream::close()
718718
try {
719719
_ibs->close();
720720
}
721-
catch (BitStreamException& e) {
721+
catch (const BitStreamException& e) {
722722
throw IOException(e.what(), e.error());
723723
}
724724

@@ -992,7 +992,7 @@ T DecodingTask<T>::run()
992992

993993
return T(*_data, blockId, decoded, checksum1, 0, "Success");
994994
}
995-
catch (exception& e) {
995+
catch (const exception& e) {
996996
// Make sure to unfreeze next block
997997
if (_processedBlockId->load(memory_order_acquire) == blockId - 1)
998998
_processedBlockId->store(blockId, memory_order_release);

src/io/CompressedOutputStream.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ CompressedOutputStream::~CompressedOutputStream()
217217
try {
218218
close();
219219
}
220-
catch (exception&) {
220+
catch (const exception&) {
221221
// Ignore and continue
222222
}
223223

@@ -395,7 +395,7 @@ void CompressedOutputStream::close()
395395
_obs->writeBits(uint64(0), 3); // write 0 (3 bits)
396396
_obs->close();
397397
}
398-
catch (exception& e) {
398+
catch (const exception& e) {
399399
setstate(ios::badbit);
400400
throw ios_base::failure(e.what());
401401
}
@@ -519,21 +519,21 @@ void CompressedOutputStream::processBlock()
519519

520520
_bufferId = 0;
521521
}
522-
catch (IOException&) {
522+
catch (const IOException&) {
523523
for (vector<EncodingTask<EncodingTaskResult>*>::iterator it = tasks.begin(); it != tasks.end(); ++it)
524524
delete *it;
525525

526526
tasks.clear();
527527
throw; // rethrow
528528
}
529-
catch (BitStreamException& e) {
529+
catch (const BitStreamException& e) {
530530
for (vector<EncodingTask<EncodingTaskResult>*>::iterator it = tasks.begin(); it != tasks.end(); ++it)
531531
delete *it;
532532

533533
tasks.clear();
534534
throw IOException(e.what(), e.error());
535535
}
536-
catch (exception& e) {
536+
catch (const exception& e) {
537537
for (vector<EncodingTask<EncodingTaskResult>*>::iterator it = tasks.begin(); it != tasks.end(); ++it)
538538
delete *it;
539539

@@ -808,7 +808,7 @@ T EncodingTask<T>::run()
808808

809809
return T(blockId, 0, "Success");
810810
}
811-
catch (exception& e) {
811+
catch (const exception& e) {
812812
// Make sure to unfreeze next block
813813
if (_processedBlockId->load(memory_order_acquire) == blockId - 1)
814814
_processedBlockId->store(blockId, memory_order_release);

src/io/CompressedOutputStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ namespace kanzi {
230230
_buffers[_bufferId]->_array[_buffers[_bufferId]->_index++] = byte(c);
231231
return *this;
232232
}
233-
catch (std::exception& e) {
233+
catch (const std::exception& e) {
234234
setstate(std::ios::badbit);
235235
throw std::ios_base::failure(e.what());
236236
}

0 commit comments

Comments
 (0)