diff options
author | Jack Lloyd <[email protected]> | 2018-11-17 16:23:51 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-11-23 11:15:25 -0500 |
commit | b909778857b3e0b7eb86ac26c818e5f25baaddbd (patch) | |
tree | f8a5c9cbec26310bbfc9077563892b04db158a48 /src/lib/compression/bzip2 | |
parent | c20a428ca2f7c1ef96e642f55bb898010444c499 (diff) |
Make exceptions easier to translate to error codes
Avoid throwing base Botan::Exception type, as it is difficult to
determine what the error is in that case.
Add Exception::error_code and Exception::error_type which allows
(for error code) more information about the error and (for error type)
allows knowing the error type without requiring a sequence of catches.
See GH #1742
Diffstat (limited to 'src/lib/compression/bzip2')
-rw-r--r-- | src/lib/compression/bzip2/bzip2.cpp | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/lib/compression/bzip2/bzip2.cpp b/src/lib/compression/bzip2/bzip2.cpp index 02d17ea07..c9dfc2ce8 100644 --- a/src/lib/compression/bzip2/bzip2.cpp +++ b/src/lib/compression/bzip2/bzip2.cpp @@ -48,10 +48,8 @@ class Bzip2_Compression_Stream final : public Bzip2_Stream int rc = BZ2_bzCompressInit(streamp(), block_size, 0, 0); - if(rc == BZ_MEM_ERROR) - throw Exception("bzip memory allocation failure"); - else if(rc != BZ_OK) - throw Exception("bzip compress initialization failed"); + if(rc != BZ_OK) + throw Compression_Error("BZ2_bzCompressInit", ErrorType::Bzip2Error, rc); } ~Bzip2_Compression_Stream() @@ -63,10 +61,8 @@ class Bzip2_Compression_Stream final : public Bzip2_Stream { int rc = BZ2_bzCompress(streamp(), flags); - if(rc == BZ_MEM_ERROR) - throw Exception("bzip memory allocation failure"); - else if(rc < 0) - throw Exception("bzip compress error " + std::to_string(-rc)); + if(rc < 0) + throw Compression_Error("BZ2_bzCompress", ErrorType::Bzip2Error, rc); return (rc == BZ_STREAM_END); } @@ -79,10 +75,8 @@ class Bzip2_Decompression_Stream final : public Bzip2_Stream { int rc = BZ2_bzDecompressInit(streamp(), 0, 0); - if(rc == BZ_MEM_ERROR) - throw Exception("bzip memory allocation failure"); - else if(rc != BZ_OK) - throw Exception("bzip decompress initialization failed"); + if(rc != BZ_OK) + throw Compression_Error("BZ2_bzDecompressInit", ErrorType::Bzip2Error, rc); } ~Bzip2_Decompression_Stream() @@ -94,10 +88,8 @@ class Bzip2_Decompression_Stream final : public Bzip2_Stream { int rc = BZ2_bzDecompress(streamp()); - if(rc == BZ_MEM_ERROR) - throw Exception("bzip memory allocation failure"); - else if(rc != BZ_OK && rc != BZ_STREAM_END) - throw Exception("bzip decompress error " + std::to_string(-rc)); + if(rc != BZ_OK && rc != BZ_STREAM_END) + throw Compression_Error("BZ2_bzDecompress", ErrorType::Bzip2Error, rc); return (rc == BZ_STREAM_END); } |