From 0fae1884079518e4f6d1c049cc7f341cd96c8a65 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sat, 19 Dec 2015 16:09:17 -0500 Subject: Remove all remaining uses of throwing a std:: exception directly See GH #340 and 6b9a3a5 for background --- src/lib/compression/bzip2/bzip2.cpp | 12 ++++++------ src/lib/compression/lzma/lzma.cpp | 6 +++--- src/lib/compression/zlib/zlib.cpp | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/lib/compression') diff --git a/src/lib/compression/bzip2/bzip2.cpp b/src/lib/compression/bzip2/bzip2.cpp index d7527bfef..09cd05919 100644 --- a/src/lib/compression/bzip2/bzip2.cpp +++ b/src/lib/compression/bzip2/bzip2.cpp @@ -42,7 +42,7 @@ class Bzip2_Compression_Stream : public Bzip2_Stream int rc = BZ2_bzCompressInit(streamp(), block_size, 0, 0); if(rc == BZ_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("bzip memory allocation failure"); else if(rc != BZ_OK) throw Exception("bzip compress initialization failed"); } @@ -57,9 +57,9 @@ class Bzip2_Compression_Stream : public Bzip2_Stream int rc = BZ2_bzCompress(streamp(), flags); if(rc == BZ_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("bzip memory allocation failure"); else if(rc < 0) - throw Exception("bzip compress error"); + throw Exception("bzip compress error " + std::to_string(-rc)); return (rc == BZ_STREAM_END); } @@ -73,7 +73,7 @@ class Bzip2_Decompression_Stream : public Bzip2_Stream int rc = BZ2_bzDecompressInit(streamp(), 0, 0); if(rc == BZ_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("bzip memory allocation failure"); else if(rc != BZ_OK) throw Exception("bzip decompress initialization failed"); } @@ -88,9 +88,9 @@ class Bzip2_Decompression_Stream : public Bzip2_Stream int rc = BZ2_bzDecompress(streamp()); if(rc == BZ_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("bzip memory allocation failure"); else if(rc != BZ_OK && rc != BZ_STREAM_END) - throw Exception("bzip decompress error"); + throw Exception("bzip decompress error " + std::to_string(-rc)); return (rc == BZ_STREAM_END); } diff --git a/src/lib/compression/lzma/lzma.cpp b/src/lib/compression/lzma/lzma.cpp index 6e5217767..5998d1c8c 100644 --- a/src/lib/compression/lzma/lzma.cpp +++ b/src/lib/compression/lzma/lzma.cpp @@ -41,7 +41,7 @@ class LZMA_Stream : public Zlib_Style_Stream lzma_ret rc = ::lzma_code(streamp(), static_cast(flags)); if(rc == LZMA_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("lzma memory allocation failed"); else if (rc != LZMA_OK && rc != LZMA_STREAM_END) throw Exception("Lzma error"); @@ -61,7 +61,7 @@ class LZMA_Compression_Stream : public LZMA_Stream lzma_ret rc = ::lzma_easy_encoder(streamp(), level, LZMA_CHECK_CRC64); if(rc == LZMA_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("lzma memory allocation failed"); else if(rc != LZMA_OK) throw Exception("lzma compress initialization failed"); } @@ -76,7 +76,7 @@ class LZMA_Decompression_Stream : public LZMA_Stream LZMA_TELL_UNSUPPORTED_CHECK); if(rc == LZMA_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("lzma memory allocation failed"); else if(rc != LZMA_OK) throw Exception("Bad setting in lzma_stream_decoder"); } diff --git a/src/lib/compression/zlib/zlib.cpp b/src/lib/compression/zlib/zlib.cpp index 10422fff7..8e1928826 100644 --- a/src/lib/compression/zlib/zlib.cpp +++ b/src/lib/compression/zlib/zlib.cpp @@ -66,7 +66,7 @@ class Zlib_Compression_Stream : public Zlib_Stream int rc = deflate(streamp(), flags); if(rc == Z_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("zlib memory allocation failure"); else if(rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) throw Exception("zlib deflate error " + std::to_string(rc)); @@ -82,7 +82,7 @@ class Zlib_Decompression_Stream : public Zlib_Stream int rc = inflateInit2(streamp(), compute_window_bits(wbits, wbits_offset)); if(rc == Z_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("zlib memory allocation failure"); else if(rc != Z_OK) throw Exception("zlib inflate initialization failed"); } @@ -97,7 +97,7 @@ class Zlib_Decompression_Stream : public Zlib_Stream int rc = inflate(streamp(), flags); if(rc == Z_MEM_ERROR) - throw std::bad_alloc(); + throw Exception("zlib memory allocation failure"); else if(rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) throw Exception("zlib inflate error " + std::to_string(rc)); -- cgit v1.2.3