diff options
| author | ljfa-ag <ljfa-ag@web.de> | 2015-09-15 10:58:49 +0200 |
|---|---|---|
| committer | ljfa-ag <ljfa-ag@web.de> | 2015-09-15 12:03:04 +0200 |
| commit | 4f96ef6b0d4aede214d208090e86cb7b8091f49c (patch) | |
| tree | e4a3a299add35da79122b6503bd6f38561c7af0d | |
| parent | 0c6f7fcccc1a9e20bbd68b5bc09bc8853d15134c (diff) | |
| download | Project-Tick-4f96ef6b0d4aede214d208090e86cb7b8091f49c.tar.gz Project-Tick-4f96ef6b0d4aede214d208090e86cb7b8091f49c.zip | |
Change zlib_error to take message and code
| -rw-r--r-- | include/io/zlib_error.h | 6 | ||||
| -rw-r--r-- | src/io/izlibstream.cpp | 7 |
2 files changed, 8 insertions, 5 deletions
diff --git a/include/io/zlib_error.h b/include/io/zlib_error.h index 12eaf20a3f..ce375a6ccd 100644 --- a/include/io/zlib_error.h +++ b/include/io/zlib_error.h @@ -2,6 +2,7 @@ #define ZLIB_ERROR_H_INCLUDED #include <stdexcept> +#include <zlib.h> ///Exception thrown in case zlib encounters a problem class zlib_error : public std::runtime_error @@ -9,8 +10,9 @@ class zlib_error : public std::runtime_error public: const int errcode; - explicit zlib_error(const char* what_arg, int errcode = -1): - std::runtime_error(what_arg), errcode(errcode) + explicit zlib_error(const char* msg, int errcode): + std::runtime_error(std::string(zError(errcode)) + ": " + msg), + errcode(errcode) {} }; diff --git a/src/io/izlibstream.cpp b/src/io/izlibstream.cpp index 9079489507..f9d9463d95 100644 --- a/src/io/izlibstream.cpp +++ b/src/io/izlibstream.cpp @@ -33,7 +33,7 @@ inflate_streambuf::inflate_streambuf(std::istream& input, size_t bufsize, int wi zstr.avail_in = 0; int ret = inflateInit2(&zstr, window_bits); if(ret != Z_OK) - throw zlib_error("inflateInit failed", ret); + throw zlib_error(zstr.msg, ret); char* end = out.data() + out.size(); setg(end, end, end); @@ -70,15 +70,16 @@ inflate_streambuf::int_type inflate_streambuf::underflow() { case Z_NEED_DICT: case Z_DATA_ERROR: - throw zlib_error("Error decompressing data", ret); + throw zlib_error(zstr.msg, ret); + case Z_MEM_ERROR: throw std::bad_alloc(); + case Z_STREAM_END: if(have == 0) return traits_type::eof(); break; } - } while(have == 0); setg(out.data(), out.data(), out.data() + have); |
