Commit f3d7c26de1f575a14017a161ad1fdd2b93385e03
1 parent
64546cfa
removed qexc; non-compatible ABI change
git-svn-id: svn+q:///qpdf/trunk@709 71b93d88-0707-0410-a8cf-f5a4172ac649
Showing
89 changed files
with
251 additions
and
651 deletions
ChangeLog
TODO
| 1 | 1 | 2.1 |
| 2 | 2 | === |
| 3 | 3 | |
| 4 | + * Be able to trap I/O errors separately from other errors; especially | |
| 5 | + be able to separate errors that the user can fix (like permission | |
| 6 | + errors) from errors that they probably can't fix like corrupted PDF | |
| 7 | + files, unsupported filters, or internal errors. | |
| 8 | + | |
| 4 | 9 | * Add ability to create new streams or replace stream data. Consider |
| 5 | 10 | stream data sources to include a file and offset, a buffer, or a |
| 6 | 11 | some kind of callback mechanism. Find messages exchanged with | ... | ... |
include/qpdf/Pipeline.hh
| ... | ... | @@ -31,27 +31,11 @@ |
| 31 | 31 | #define __PIPELINE_HH__ |
| 32 | 32 | |
| 33 | 33 | #include <qpdf/DLL.hh> |
| 34 | - | |
| 35 | -#include <qpdf/QEXC.hh> | |
| 34 | +#include <string> | |
| 36 | 35 | |
| 37 | 36 | class Pipeline |
| 38 | 37 | { |
| 39 | 38 | public: |
| 40 | - class Exception: public QEXC::General | |
| 41 | - { | |
| 42 | - public: | |
| 43 | - DLL_EXPORT | |
| 44 | - Exception(std::string const& message) : | |
| 45 | - QEXC::General(message) | |
| 46 | - { | |
| 47 | - } | |
| 48 | - | |
| 49 | - DLL_EXPORT | |
| 50 | - virtual ~Exception() throw() | |
| 51 | - { | |
| 52 | - } | |
| 53 | - }; | |
| 54 | - | |
| 55 | 39 | DLL_EXPORT |
| 56 | 40 | Pipeline(char const* identifier, Pipeline* next); |
| 57 | 41 | ... | ... |
include/qpdf/Pl_Flate.hh
| ... | ... | @@ -15,21 +15,6 @@ |
| 15 | 15 | class Pl_Flate: public Pipeline |
| 16 | 16 | { |
| 17 | 17 | public: |
| 18 | - class Exception: public Pipeline::Exception | |
| 19 | - { | |
| 20 | - public: | |
| 21 | - DLL_EXPORT | |
| 22 | - Exception(std::string const& message) : | |
| 23 | - Pipeline::Exception(message) | |
| 24 | - { | |
| 25 | - } | |
| 26 | - | |
| 27 | - DLL_EXPORT | |
| 28 | - virtual ~Exception() throw () | |
| 29 | - { | |
| 30 | - } | |
| 31 | - }; | |
| 32 | - | |
| 33 | 18 | static int const def_bufsize = 65536; |
| 34 | 19 | |
| 35 | 20 | enum action_e { a_inflate, a_deflate }; | ... | ... |
include/qpdf/Pl_StdioFile.hh
| ... | ... | @@ -21,21 +21,6 @@ |
| 21 | 21 | class Pl_StdioFile: public Pipeline |
| 22 | 22 | { |
| 23 | 23 | public: |
| 24 | - class Exception: public Pipeline::Exception | |
| 25 | - { | |
| 26 | - public: | |
| 27 | - DLL_EXPORT | |
| 28 | - Exception(std::string const& message) : | |
| 29 | - Pipeline::Exception(message) | |
| 30 | - { | |
| 31 | - } | |
| 32 | - | |
| 33 | - DLL_EXPORT | |
| 34 | - virtual ~Exception() throw () | |
| 35 | - { | |
| 36 | - } | |
| 37 | - }; | |
| 38 | - | |
| 39 | 24 | // f is externally maintained; this class just writes to and |
| 40 | 25 | // flushes it. It does not close it. |
| 41 | 26 | DLL_EXPORT | ... | ... |
include/qpdf/QEXC.hh deleted
| 1 | -// Copyright (c) 2005-2009 Jay Berkenbilt | |
| 2 | -// | |
| 3 | -// This file is part of qpdf. This software may be distributed under | |
| 4 | -// the terms of version 2 of the Artistic License which may be found | |
| 5 | -// in the source distribution. It is provided "as is" without express | |
| 6 | -// or implied warranty. | |
| 7 | - | |
| 8 | -#ifndef __QEXC_HH__ | |
| 9 | -#define __QEXC_HH__ | |
| 10 | - | |
| 11 | -#include <qpdf/DLL.hh> | |
| 12 | - | |
| 13 | -#include <string> | |
| 14 | -#include <exception> | |
| 15 | -#include <errno.h> | |
| 16 | - | |
| 17 | -namespace QEXC | |
| 18 | -{ | |
| 19 | - // This namespace contains all exception classes used by the | |
| 20 | - // library. | |
| 21 | - | |
| 22 | - // The class hierarchy is as follows: | |
| 23 | - | |
| 24 | - // std::exception | |
| 25 | - // | | |
| 26 | - // +-> QEXC::Base | |
| 27 | - // | | |
| 28 | - // +-> QEXC::General | |
| 29 | - // | | |
| 30 | - // +-> QEXC::Internal | |
| 31 | - | |
| 32 | - // QEXC::General is the base class of all standard user-defined | |
| 33 | - // exceptions and "expected" error conditions raised by QClass. | |
| 34 | - // Applications or libraries using QClass are encouraged to derive | |
| 35 | - // their own exceptions from these classes if they wish. It is | |
| 36 | - // entirely reasonable for code to catch QEXC::General or specific | |
| 37 | - // subclasses of it as part of normal error handling. | |
| 38 | - | |
| 39 | - // QEXC::Internal is reserved for internal errors. These should | |
| 40 | - // be used only for situations that indicate a likely bug in the | |
| 41 | - // software itself. This may include improper use of a library | |
| 42 | - // function. Operator errors should not be able to cause Internal | |
| 43 | - // errors. (There may be some exceptions to this such as users | |
| 44 | - // invoking programs that were intended only to be invoked by | |
| 45 | - // other programs.) QEXC::Internal should generally not be | |
| 46 | - // trapped except in terminate handlers or top-level exception | |
| 47 | - // handlers which will want to translate them into error messages | |
| 48 | - // and cause the program to exit. Such top-level handlers may | |
| 49 | - // want to catch std::exception instead. | |
| 50 | - | |
| 51 | - // All subclasses of QEXC::Base implement a const unparse() method | |
| 52 | - // which returns a std::string const&. They also override | |
| 53 | - // std::exception::what() to return a char* with the same value. | |
| 54 | - // unparse() should be implemented in such a way that a program | |
| 55 | - // catching QEXC::Base or std::exception can use the text returned | |
| 56 | - // by unparse() (or what()) without any exception-specific | |
| 57 | - // adornment. (The program may prefix the program name or other | |
| 58 | - // general information.) Note that std::exception::what() is a | |
| 59 | - // const method that returns a const char*. For this reason, it | |
| 60 | - // is essential that unparse() return a const reference to a | |
| 61 | - // string so that what() can be implemented by calling unparse(). | |
| 62 | - // This means that the string that unparse() returns a reference | |
| 63 | - // to must not be allocated on the stack in the call to unparse(). | |
| 64 | - // The recommended way to do this is for derived exception classes | |
| 65 | - // to store their string descriptions by calling the protected | |
| 66 | - // setMessage() method and then to not override unparse(). | |
| 67 | - | |
| 68 | - class Base: public std::exception | |
| 69 | - { | |
| 70 | - // This is the common base class for all exceptions in qclass. | |
| 71 | - // Application/library code should not generally catch this | |
| 72 | - // directly. See above for caveats. | |
| 73 | - public: | |
| 74 | - DLL_EXPORT | |
| 75 | - Base(); | |
| 76 | - DLL_EXPORT | |
| 77 | - Base(std::string const& message); | |
| 78 | - DLL_EXPORT | |
| 79 | - virtual ~Base() throw() {} | |
| 80 | - DLL_EXPORT | |
| 81 | - virtual std::string const& unparse() const; | |
| 82 | - DLL_EXPORT | |
| 83 | - virtual const char* what() const throw(); | |
| 84 | - | |
| 85 | - protected: | |
| 86 | - DLL_EXPORT | |
| 87 | - void setMessage(std::string const& message); | |
| 88 | - | |
| 89 | - private: | |
| 90 | - std::string message; | |
| 91 | - }; | |
| 92 | - | |
| 93 | - class General: public Base | |
| 94 | - { | |
| 95 | - // This is the base class for normal user/library-defined | |
| 96 | - // error conditions. | |
| 97 | - public: | |
| 98 | - DLL_EXPORT | |
| 99 | - General(); | |
| 100 | - DLL_EXPORT | |
| 101 | - General(std::string const& message); | |
| 102 | - DLL_EXPORT | |
| 103 | - virtual ~General() throw() {}; | |
| 104 | - }; | |
| 105 | - | |
| 106 | - // Note that Internal is not derived from General. Internal | |
| 107 | - // errors are too severe. We don't want internal errors | |
| 108 | - // accidentally trapped as part of QEXC::General. If you are | |
| 109 | - // going to deal with internal errors, you have to do so | |
| 110 | - // explicitly. | |
| 111 | - class Internal: public Base | |
| 112 | - { | |
| 113 | - public: | |
| 114 | - DLL_EXPORT | |
| 115 | - Internal(std::string const& message); | |
| 116 | - DLL_EXPORT | |
| 117 | - virtual ~Internal() throw() {}; | |
| 118 | - }; | |
| 119 | - | |
| 120 | - class System: public General | |
| 121 | - { | |
| 122 | - public: | |
| 123 | - DLL_EXPORT | |
| 124 | - System(std::string const& prefix, int sys_errno); | |
| 125 | - DLL_EXPORT | |
| 126 | - virtual ~System() throw() {}; | |
| 127 | - DLL_EXPORT | |
| 128 | - int getErrno() const; | |
| 129 | - | |
| 130 | - private: | |
| 131 | - int sys_errno; | |
| 132 | - }; | |
| 133 | -}; | |
| 134 | - | |
| 135 | -#endif // __QEXC_HH__ |
include/qpdf/QPDFExc.hh
| ... | ... | @@ -8,9 +8,10 @@ |
| 8 | 8 | #ifndef __QPDFEXC_HH__ |
| 9 | 9 | #define __QPDFEXC_HH__ |
| 10 | 10 | |
| 11 | -#include <qpdf/QEXC.hh> | |
| 11 | +#include <qpdf/DLL.hh> | |
| 12 | +#include <stdexcept> | |
| 12 | 13 | |
| 13 | -class QPDFExc: public QEXC::General | |
| 14 | +class QPDFExc: public std::runtime_error | |
| 14 | 15 | { |
| 15 | 16 | public: |
| 16 | 17 | DLL_EXPORT | ... | ... |
include/qpdf/QUtil.hh
| ... | ... | @@ -8,13 +8,13 @@ |
| 8 | 8 | #ifndef __QUTIL_HH__ |
| 9 | 9 | #define __QUTIL_HH__ |
| 10 | 10 | |
| 11 | +#include <qpdf/DLL.hh> | |
| 11 | 12 | #include <string> |
| 12 | 13 | #include <list> |
| 14 | +#include <stdexcept> | |
| 13 | 15 | #include <stdio.h> |
| 14 | 16 | #include <sys/stat.h> |
| 15 | 17 | |
| 16 | -#include <qpdf/QEXC.hh> | |
| 17 | - | |
| 18 | 18 | namespace QUtil |
| 19 | 19 | { |
| 20 | 20 | // This is a collection of useful utility functions that don't |
| ... | ... | @@ -24,15 +24,25 @@ namespace QUtil |
| 24 | 24 | DLL_EXPORT |
| 25 | 25 | std::string double_to_string(double, int decimal_places = 0); |
| 26 | 26 | |
| 27 | - // If status is -1, convert the current value of errno to a | |
| 28 | - // QEXC::System exception. Otherwise, return status. | |
| 27 | + // Throw std::runtime_error with a string formed by appending to | |
| 28 | + // "description: " the standard string corresponding to the | |
| 29 | + // current value of errno. | |
| 30 | + DLL_EXPORT | |
| 31 | + void throw_system_error(std::string const& description); | |
| 32 | + | |
| 33 | + // The status argument is assumed to be the return value of a | |
| 34 | + // standard library call that sets errno when it fails. If status | |
| 35 | + // is -1, convert the current value of errno to a | |
| 36 | + // std::runtime_error that includes the standard error string. | |
| 37 | + // Otherwise, return status. | |
| 29 | 38 | DLL_EXPORT |
| 30 | - int os_wrapper(std::string const& description, int status) | |
| 31 | - throw (QEXC::System); | |
| 39 | + int os_wrapper(std::string const& description, int status); | |
| 32 | 40 | |
| 41 | + // The FILE* argument is assumed to be the return of fopen. If | |
| 42 | + // null, throw std::runtime_error. Otherwise, return the FILE* | |
| 43 | + // argument. | |
| 33 | 44 | DLL_EXPORT |
| 34 | - FILE* fopen_wrapper(std::string const&, FILE*) | |
| 35 | - throw (QEXC::System); | |
| 45 | + FILE* fopen_wrapper(std::string const&, FILE*); | |
| 36 | 46 | |
| 37 | 47 | DLL_EXPORT |
| 38 | 48 | char* copy_string(std::string const&); | ... | ... |
libqpdf/BitStream.cc
| ... | ... | @@ -38,7 +38,8 @@ BitStream::skipToNextByte() |
| 38 | 38 | unsigned int bits_to_skip = bit_offset + 1; |
| 39 | 39 | if (bits_available < bits_to_skip) |
| 40 | 40 | { |
| 41 | - throw QEXC::Internal("overflow skipping to next byte in bitstream"); | |
| 41 | + throw std::logic_error( | |
| 42 | + "INTERNAL ERROR: overflow skipping to next byte in bitstream"); | |
| 42 | 43 | } |
| 43 | 44 | bit_offset = 7; |
| 44 | 45 | ++p; | ... | ... |
libqpdf/BitWriter.cc
libqpdf/Buffer.cc
libqpdf/MD5.cc
| ... | ... | @@ -28,6 +28,7 @@ |
| 28 | 28 | ///////////////////////////////////////////////////////////////////////// |
| 29 | 29 | |
| 30 | 30 | #include <qpdf/MD5.hh> |
| 31 | +#include <qpdf/QUtil.hh> | |
| 31 | 32 | |
| 32 | 33 | #include <stdio.h> |
| 33 | 34 | #include <memory.h> |
| ... | ... | @@ -330,15 +331,12 @@ void MD5::encodeDataIncrementally(char const* data, int len) |
| 330 | 331 | |
| 331 | 332 | DLL_EXPORT |
| 332 | 333 | void MD5::encodeFile(char const *filename, int up_to_size) |
| 333 | - throw (QEXC::System) | |
| 334 | 334 | { |
| 335 | - FILE *file; | |
| 336 | 335 | unsigned char buffer[1024]; |
| 337 | 336 | |
| 338 | - if ((file = fopen (filename, "rb")) == NULL) | |
| 339 | - { | |
| 340 | - throw QEXC::System(std::string("MD5: can't open ") + filename, errno); | |
| 341 | - } | |
| 337 | + FILE *file = QUtil::fopen_wrapper( | |
| 338 | + std::string("MD5: open ") + filename, | |
| 339 | + fopen(filename, "rb")); | |
| 342 | 340 | |
| 343 | 341 | int len; |
| 344 | 342 | int so_far = 0; |
| ... | ... | @@ -365,7 +363,8 @@ void MD5::encodeFile(char const *filename, int up_to_size) |
| 365 | 363 | // Assume, perhaps incorrectly, that errno was set by the |
| 366 | 364 | // underlying call to read.... |
| 367 | 365 | (void) fclose(file); |
| 368 | - throw QEXC::System(std::string("MD5: read error on ") + filename, errno); | |
| 366 | + QUtil::throw_system_error( | |
| 367 | + std::string("MD5: read error on ") + filename); | |
| 369 | 368 | } |
| 370 | 369 | (void) fclose(file); |
| 371 | 370 | |
| ... | ... | @@ -446,7 +445,7 @@ MD5::checkFileChecksum(char const* const checksum, |
| 446 | 445 | std::string actual_checksum = getFileChecksum(filename, up_to_size); |
| 447 | 446 | result = (checksum == actual_checksum); |
| 448 | 447 | } |
| 449 | - catch (QEXC::System) | |
| 448 | + catch (std::runtime_error) | |
| 450 | 449 | { |
| 451 | 450 | // Ignore -- return false |
| 452 | 451 | } | ... | ... |
libqpdf/PCRE.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/PCRE.hh> |
| 3 | 2 | #include <qpdf/QUtil.hh> |
| 4 | 3 | |
| 4 | +#include <stdexcept> | |
| 5 | 5 | #include <iostream> |
| 6 | 6 | #include <string.h> |
| 7 | 7 | |
| 8 | 8 | DLL_EXPORT |
| 9 | -PCRE::Exception::Exception(std::string const& message) | |
| 10 | -{ | |
| 11 | - this->setMessage("PCRE error: " + message); | |
| 12 | -} | |
| 13 | - | |
| 14 | -DLL_EXPORT | |
| 15 | 9 | PCRE::NoBackref::NoBackref() : |
| 16 | - Exception("no match") | |
| 10 | + std::logic_error("PCRE error: no match") | |
| 17 | 11 | { |
| 18 | 12 | } |
| 19 | 13 | |
| ... | ... | @@ -87,7 +81,6 @@ PCRE::Match::operator bool() |
| 87 | 81 | DLL_EXPORT |
| 88 | 82 | std::string |
| 89 | 83 | PCRE::Match::getMatch(int n, int flags) |
| 90 | - throw(QEXC::General, Exception) | |
| 91 | 84 | { |
| 92 | 85 | // This method used to be implemented in terms of |
| 93 | 86 | // pcre_get_substring, but that function gives you an empty string |
| ... | ... | @@ -116,7 +109,7 @@ PCRE::Match::getMatch(int n, int flags) |
| 116 | 109 | |
| 117 | 110 | DLL_EXPORT |
| 118 | 111 | void |
| 119 | -PCRE::Match::getOffsetLength(int n, int& offset, int& length) throw(Exception) | |
| 112 | +PCRE::Match::getOffsetLength(int n, int& offset, int& length) | |
| 120 | 113 | { |
| 121 | 114 | if ((this->nmatches < 0) || |
| 122 | 115 | (n > this->nmatches - 1) || |
| ... | ... | @@ -130,7 +123,7 @@ PCRE::Match::getOffsetLength(int n, int& offset, int& length) throw(Exception) |
| 130 | 123 | |
| 131 | 124 | DLL_EXPORT |
| 132 | 125 | int |
| 133 | -PCRE::Match::getOffset(int n) throw(Exception) | |
| 126 | +PCRE::Match::getOffset(int n) | |
| 134 | 127 | { |
| 135 | 128 | int offset; |
| 136 | 129 | int length; |
| ... | ... | @@ -140,7 +133,7 @@ PCRE::Match::getOffset(int n) throw(Exception) |
| 140 | 133 | |
| 141 | 134 | DLL_EXPORT |
| 142 | 135 | int |
| 143 | -PCRE::Match::getLength(int n) throw(Exception) | |
| 136 | +PCRE::Match::getLength(int n) | |
| 144 | 137 | { |
| 145 | 138 | int offset; |
| 146 | 139 | int length; |
| ... | ... | @@ -156,7 +149,7 @@ PCRE::Match::nMatches() const |
| 156 | 149 | } |
| 157 | 150 | |
| 158 | 151 | DLL_EXPORT |
| 159 | -PCRE::PCRE(char const* pattern, int options) throw (PCRE::Exception) | |
| 152 | +PCRE::PCRE(char const* pattern, int options) | |
| 160 | 153 | { |
| 161 | 154 | char const *errptr; |
| 162 | 155 | int erroffset; |
| ... | ... | @@ -171,7 +164,7 @@ PCRE::PCRE(char const* pattern, int options) throw (PCRE::Exception) |
| 171 | 164 | " failed at offset " + |
| 172 | 165 | QUtil::int_to_string(erroffset) + ": " + |
| 173 | 166 | errptr); |
| 174 | - throw Exception(message); | |
| 167 | + throw std::runtime_error("PCRE error: " + message); | |
| 175 | 168 | } |
| 176 | 169 | } |
| 177 | 170 | |
| ... | ... | @@ -184,7 +177,6 @@ PCRE::~PCRE() |
| 184 | 177 | DLL_EXPORT |
| 185 | 178 | PCRE::Match |
| 186 | 179 | PCRE::match(char const* subject, int options, int startoffset, int size) |
| 187 | - throw (QEXC::General, Exception) | |
| 188 | 180 | { |
| 189 | 181 | if (size == -1) |
| 190 | 182 | { |
| ... | ... | @@ -210,12 +202,12 @@ PCRE::match(char const* subject, int options, int startoffset, int size) |
| 210 | 202 | |
| 211 | 203 | case PCRE_ERROR_BADOPTION: |
| 212 | 204 | message = "bad option passed to PCRE::match()"; |
| 213 | - throw Exception(message); | |
| 205 | + throw std::logic_error(message); | |
| 214 | 206 | break; |
| 215 | 207 | |
| 216 | 208 | case PCRE_ERROR_NOMEMORY: |
| 217 | 209 | message = "insufficient memory"; |
| 218 | - throw Exception(message); | |
| 210 | + throw std::runtime_error(message); | |
| 219 | 211 | break; |
| 220 | 212 | |
| 221 | 213 | case PCRE_ERROR_NULL: |
| ... | ... | @@ -223,7 +215,7 @@ PCRE::match(char const* subject, int options, int startoffset, int size) |
| 223 | 215 | case PCRE_ERROR_UNKNOWN_NODE: |
| 224 | 216 | default: |
| 225 | 217 | message = "pcre_exec returned " + QUtil::int_to_string(status); |
| 226 | - throw QEXC::Internal(message); | |
| 218 | + throw std::logic_error(message); | |
| 227 | 219 | } |
| 228 | 220 | } |
| 229 | 221 | |
| ... | ... | @@ -258,9 +250,9 @@ PCRE::test(int n) |
| 258 | 250 | { |
| 259 | 251 | PCRE pcre1("a**"); |
| 260 | 252 | } |
| 261 | - catch (Exception& e) | |
| 253 | + catch (std::exception& e) | |
| 262 | 254 | { |
| 263 | - std::cout << e.unparse() << std::endl; | |
| 255 | + std::cout << e.what() << std::endl; | |
| 264 | 256 | } |
| 265 | 257 | |
| 266 | 258 | PCRE pcre2("^([^\\s:]*)\\s*:\\s*(.*?)\\s*$"); |
| ... | ... | @@ -281,17 +273,17 @@ PCRE::test(int n) |
| 281 | 273 | { |
| 282 | 274 | std::cout << m2.getMatch(3) << std::endl; |
| 283 | 275 | } |
| 284 | - catch (Exception& e) | |
| 276 | + catch (std::exception& e) | |
| 285 | 277 | { |
| 286 | - std::cout << e.unparse() << std::endl; | |
| 278 | + std::cout << e.what() << std::endl; | |
| 287 | 279 | } |
| 288 | 280 | try |
| 289 | 281 | { |
| 290 | 282 | std::cout << m2.getOffset(3) << std::endl; |
| 291 | 283 | } |
| 292 | - catch (Exception& e) | |
| 284 | + catch (std::exception& e) | |
| 293 | 285 | { |
| 294 | - std::cout << e.unparse() << std::endl; | |
| 286 | + std::cout << e.what() << std::endl; | |
| 295 | 287 | } |
| 296 | 288 | } |
| 297 | 289 | PCRE pcre3("^(a+)(b+)?$"); |
| ... | ... | @@ -312,9 +304,9 @@ PCRE::test(int n) |
| 312 | 304 | std::cout << "can't see this" << std::endl; |
| 313 | 305 | } |
| 314 | 306 | } |
| 315 | - catch (Exception& e) | |
| 307 | + catch (std::exception& e) | |
| 316 | 308 | { |
| 317 | - std::cout << e.unparse() << std::endl; | |
| 309 | + std::cout << e.what() << std::endl; | |
| 318 | 310 | } |
| 319 | 311 | |
| 320 | 312 | // backref: 1 2 3 4 5 |
| ... | ... | @@ -370,8 +362,8 @@ PCRE::test(int n) |
| 370 | 362 | } |
| 371 | 363 | } |
| 372 | 364 | } |
| 373 | - catch (QEXC::General& e) | |
| 365 | + catch (std::exception& e) | |
| 374 | 366 | { |
| 375 | - std::cout << "unexpected exception: " << e.unparse() << std::endl; | |
| 367 | + std::cout << "unexpected exception: " << e.what() << std::endl; | |
| 376 | 368 | } |
| 377 | 369 | } | ... | ... |
libqpdf/Pipeline.cc
| 1 | - | |
| 2 | - | |
| 3 | 1 | #include <qpdf/Pipeline.hh> |
| 2 | +#include <stdexcept> | |
| 4 | 3 | |
| 5 | 4 | DLL_EXPORT |
| 6 | 5 | Pipeline::Pipeline(char const* identifier, Pipeline* next) : |
| ... | ... | @@ -19,7 +18,7 @@ Pipeline::getNext(bool allow_null) |
| 19 | 18 | { |
| 20 | 19 | if ((next == 0) && (! allow_null)) |
| 21 | 20 | { |
| 22 | - throw Exception( | |
| 21 | + throw std::logic_error( | |
| 23 | 22 | this->identifier + |
| 24 | 23 | ": Pipeline::getNext() called on pipeline with no next"); |
| 25 | 24 | } | ... | ... |
libqpdf/Pl_ASCII85Decoder.cc
| 1 | 1 | #include <qpdf/Pl_ASCII85Decoder.hh> |
| 2 | -#include <qpdf/QEXC.hh> | |
| 3 | 2 | #include <qpdf/QTC.hh> |
| 3 | +#include <stdexcept> | |
| 4 | 4 | #include <string.h> |
| 5 | 5 | |
| 6 | 6 | DLL_EXPORT |
| ... | ... | @@ -40,7 +40,7 @@ Pl_ASCII85Decoder::write(unsigned char* buf, int len) |
| 40 | 40 | } |
| 41 | 41 | else |
| 42 | 42 | { |
| 43 | - throw QEXC::General( | |
| 43 | + throw std::runtime_error( | |
| 44 | 44 | "broken end-of-data sequence in base 85 data"); |
| 45 | 45 | } |
| 46 | 46 | } |
| ... | ... | @@ -65,7 +65,7 @@ Pl_ASCII85Decoder::write(unsigned char* buf, int len) |
| 65 | 65 | case 'z': |
| 66 | 66 | if (pos != 0) |
| 67 | 67 | { |
| 68 | - throw QEXC::General( | |
| 68 | + throw std::runtime_error( | |
| 69 | 69 | "unexpected z during base 85 decode"); |
| 70 | 70 | } |
| 71 | 71 | else |
| ... | ... | @@ -78,8 +78,8 @@ Pl_ASCII85Decoder::write(unsigned char* buf, int len) |
| 78 | 78 | default: |
| 79 | 79 | if ((buf[i] < 33) || (buf[i] > 117)) |
| 80 | 80 | { |
| 81 | - throw QEXC::General | |
| 82 | - ("character out of range during base 85 decode"); | |
| 81 | + throw std::runtime_error( | |
| 82 | + "character out of range during base 85 decode"); | |
| 83 | 83 | } |
| 84 | 84 | else |
| 85 | 85 | { | ... | ... |
libqpdf/Pl_ASCIIHexDecoder.cc
| 1 | 1 | #include <qpdf/Pl_ASCIIHexDecoder.hh> |
| 2 | -#include <qpdf/QEXC.hh> | |
| 3 | 2 | #include <qpdf/QTC.hh> |
| 3 | +#include <stdexcept> | |
| 4 | 4 | #include <string.h> |
| 5 | 5 | #include <ctype.h> |
| 6 | 6 | |
| ... | ... | @@ -61,8 +61,9 @@ Pl_ASCIIHexDecoder::write(unsigned char* buf, int len) |
| 61 | 61 | char t[2]; |
| 62 | 62 | t[0] = ch; |
| 63 | 63 | t[1] = 0; |
| 64 | - throw QEXC::General( | |
| 65 | - std::string("character out of range during base Hex decode: ") + t); | |
| 64 | + throw std::runtime_error( | |
| 65 | + std::string("character out of range" | |
| 66 | + " during base Hex decode: ") + t); | |
| 66 | 67 | } |
| 67 | 68 | break; |
| 68 | 69 | } | ... | ... |
libqpdf/Pl_Buffer.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/Pl_Buffer.hh> |
| 3 | -#include <qpdf/QEXC.hh> | |
| 2 | +#include <stdexcept> | |
| 4 | 3 | #include <assert.h> |
| 5 | 4 | #include <string.h> |
| 6 | 5 | |
| ... | ... | @@ -50,7 +49,7 @@ Pl_Buffer::getBuffer() |
| 50 | 49 | { |
| 51 | 50 | if (! this->ready) |
| 52 | 51 | { |
| 53 | - throw QEXC::Internal("Pl_Buffer::getBuffer() called when not ready"); | |
| 52 | + throw std::logic_error("Pl_Buffer::getBuffer() called when not ready"); | |
| 54 | 53 | } |
| 55 | 54 | |
| 56 | 55 | Buffer* b = new Buffer(this->total_size); | ... | ... |
libqpdf/Pl_Count.cc
libqpdf/Pl_Discard.cc
libqpdf/Pl_Flate.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/Pl_Flate.hh> |
| 3 | 2 | |
| 4 | 3 | #include <qpdf/QUtil.hh> |
| ... | ... | @@ -38,7 +37,7 @@ Pl_Flate::write(unsigned char* data, int len) |
| 38 | 37 | { |
| 39 | 38 | if (this->outbuf == 0) |
| 40 | 39 | { |
| 41 | - throw Exception( | |
| 40 | + throw std::logic_error( | |
| 42 | 41 | this->identifier + |
| 43 | 42 | ": Pl_Flate: write() called after finish() called"); |
| 44 | 43 | } |
| ... | ... | @@ -197,6 +196,6 @@ Pl_Flate::checkError(char const* prefix, int error_code) |
| 197 | 196 | } |
| 198 | 197 | } |
| 199 | 198 | |
| 200 | - throw Exception(msg); | |
| 199 | + throw std::runtime_error(msg); | |
| 201 | 200 | } |
| 202 | 201 | } | ... | ... |
libqpdf/Pl_LZWDecoder.cc
| 1 | 1 | #include <qpdf/Pl_LZWDecoder.hh> |
| 2 | 2 | |
| 3 | -#include <qpdf/QEXC.hh> | |
| 4 | 3 | #include <qpdf/QTC.hh> |
| 4 | +#include <stdexcept> | |
| 5 | 5 | #include <string.h> |
| 6 | 6 | #include <assert.h> |
| 7 | 7 | |
| ... | ... | @@ -185,7 +185,7 @@ Pl_LZWDecoder::handleCode(int code) |
| 185 | 185 | unsigned int idx = code - 258; |
| 186 | 186 | if (idx > table_size) |
| 187 | 187 | { |
| 188 | - throw QEXC::General("LZWDecoder: bad code received"); | |
| 188 | + throw std::runtime_error("LZWDecoder: bad code received"); | |
| 189 | 189 | } |
| 190 | 190 | else if (idx == table_size) |
| 191 | 191 | { |
| ... | ... | @@ -204,7 +204,7 @@ Pl_LZWDecoder::handleCode(int code) |
| 204 | 204 | unsigned int new_idx = 258 + table_size; |
| 205 | 205 | if (new_idx == 4096) |
| 206 | 206 | { |
| 207 | - throw QEXC::General("LZWDecoder: table full"); | |
| 207 | + throw std::runtime_error("LZWDecoder: table full"); | |
| 208 | 208 | } |
| 209 | 209 | addToTable(next); |
| 210 | 210 | unsigned int change_idx = new_idx + code_change_delta; | ... | ... |
libqpdf/Pl_MD5.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/Pl_MD5.hh> |
| 3 | - | |
| 4 | -#include <qpdf/QEXC.hh> | |
| 2 | +#include <stdexcept> | |
| 5 | 3 | |
| 6 | 4 | DLL_EXPORT |
| 7 | 5 | Pl_MD5::Pl_MD5(char const* identifier, Pipeline* next) : |
| ... | ... | @@ -42,7 +40,8 @@ Pl_MD5::getHexDigest() |
| 42 | 40 | { |
| 43 | 41 | if (this->in_progress) |
| 44 | 42 | { |
| 45 | - throw QEXC::General("digest requested for in-progress MD5 Pipeline"); | |
| 43 | + throw std::logic_error( | |
| 44 | + "digest requested for in-progress MD5 Pipeline"); | |
| 46 | 45 | } |
| 47 | 46 | return this->md5.unparse(); |
| 48 | 47 | } | ... | ... |
libqpdf/Pl_PNGFilter.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/Pl_PNGFilter.hh> |
| 2 | +#include <stdexcept> | |
| 3 | 3 | #include <string.h> |
| 4 | 4 | |
| 5 | 5 | DLL_EXPORT |
| ... | ... | @@ -85,7 +85,7 @@ Pl_PNGFilter::decodeRow() |
| 85 | 85 | break; |
| 86 | 86 | |
| 87 | 87 | case 1: // sub |
| 88 | - throw Exception("sub filter not implemented"); | |
| 88 | + throw std::logic_error("sub filter not implemented"); | |
| 89 | 89 | break; |
| 90 | 90 | |
| 91 | 91 | case 2: // up |
| ... | ... | @@ -96,11 +96,11 @@ Pl_PNGFilter::decodeRow() |
| 96 | 96 | break; |
| 97 | 97 | |
| 98 | 98 | case 3: // average |
| 99 | - throw Exception("average filter not implemented"); | |
| 99 | + throw std::logic_error("average filter not implemented"); | |
| 100 | 100 | break; |
| 101 | 101 | |
| 102 | 102 | case 4: // Paeth |
| 103 | - throw Exception("Paeth filter not implemented"); | |
| 103 | + throw std::logic_error("Paeth filter not implemented"); | |
| 104 | 104 | break; |
| 105 | 105 | |
| 106 | 106 | default: | ... | ... |
libqpdf/Pl_QPDFTokenizer.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/Pl_QPDFTokenizer.hh> |
| 3 | 2 | #include <qpdf/QPDF_String.hh> |
| 4 | 3 | #include <qpdf/QPDF_Name.hh> |
| 4 | +#include <stdexcept> | |
| 5 | 5 | #include <string.h> |
| 6 | 6 | |
| 7 | 7 | Pl_QPDFTokenizer::Pl_QPDFTokenizer(char const* identifier, Pipeline* next) : |
| ... | ... | @@ -134,8 +134,9 @@ Pl_QPDFTokenizer::checkUnread() |
| 134 | 134 | processChar(this->char_to_unread); |
| 135 | 135 | if (this->unread_char) |
| 136 | 136 | { |
| 137 | - throw QEXC::Internal("unread_char still true after processing " | |
| 138 | - "unread character"); | |
| 137 | + throw std::logic_error( | |
| 138 | + "INTERNAL ERROR: unread_char still true after processing " | |
| 139 | + "unread character"); | |
| 139 | 140 | } |
| 140 | 141 | } |
| 141 | 142 | } | ... | ... |
libqpdf/Pl_RC4.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/Pl_RC4.hh> |
| 3 | - | |
| 4 | 2 | #include <qpdf/QUtil.hh> |
| 5 | 3 | |
| 6 | 4 | DLL_EXPORT |
| ... | ... | @@ -30,7 +28,7 @@ Pl_RC4::write(unsigned char* data, int len) |
| 30 | 28 | { |
| 31 | 29 | if (this->outbuf == 0) |
| 32 | 30 | { |
| 33 | - throw Exception( | |
| 31 | + throw std::logic_error( | |
| 34 | 32 | this->identifier + |
| 35 | 33 | ": Pl_RC4: write() called after finish() called"); |
| 36 | 34 | } | ... | ... |
libqpdf/Pl_StdioFile.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/Pl_StdioFile.hh> |
| 3 | - | |
| 2 | +#include <qpdf/QUtil.hh> | |
| 3 | +#include <stdexcept> | |
| 4 | 4 | #include <errno.h> |
| 5 | 5 | |
| 6 | 6 | DLL_EXPORT |
| ... | ... | @@ -25,8 +25,8 @@ Pl_StdioFile::write(unsigned char* buf, int len) |
| 25 | 25 | so_far = fwrite(buf, 1, len, this->file); |
| 26 | 26 | if (so_far == 0) |
| 27 | 27 | { |
| 28 | - throw QEXC::System(this->identifier + ": Pl_StdioFile::write", | |
| 29 | - errno); | |
| 28 | + QUtil::throw_system_error( | |
| 29 | + this->identifier + ": Pl_StdioFile::write"); | |
| 30 | 30 | } |
| 31 | 31 | else |
| 32 | 32 | { |
| ... | ... | @@ -46,7 +46,8 @@ Pl_StdioFile::finish() |
| 46 | 46 | } |
| 47 | 47 | else |
| 48 | 48 | { |
| 49 | - throw QEXC::Internal(this->identifier + | |
| 50 | - ": Pl_StdioFile::finish: stream already closed"); | |
| 49 | + throw std::logic_error( | |
| 50 | + this->identifier + | |
| 51 | + ": Pl_StdioFile::finish: stream already closed"); | |
| 51 | 52 | } |
| 52 | 53 | } | ... | ... |
libqpdf/QEXC.cc deleted
| 1 | - | |
| 2 | -#include <qpdf/QEXC.hh> | |
| 3 | -#include <string.h> | |
| 4 | -#include <errno.h> | |
| 5 | - | |
| 6 | -DLL_EXPORT | |
| 7 | -QEXC::Base::Base() | |
| 8 | -{ | |
| 9 | - // nothing needed | |
| 10 | -} | |
| 11 | - | |
| 12 | -DLL_EXPORT | |
| 13 | -QEXC::Base::Base(std::string const& message) : | |
| 14 | - message(message) | |
| 15 | -{ | |
| 16 | - // nothing needed | |
| 17 | -} | |
| 18 | - | |
| 19 | -DLL_EXPORT | |
| 20 | -std::string const& | |
| 21 | -QEXC::Base::unparse() const | |
| 22 | -{ | |
| 23 | - return this->message; | |
| 24 | -} | |
| 25 | - | |
| 26 | -DLL_EXPORT | |
| 27 | -void | |
| 28 | -QEXC::Base::setMessage(std::string const& message) | |
| 29 | -{ | |
| 30 | - this->message = message; | |
| 31 | -} | |
| 32 | - | |
| 33 | -DLL_EXPORT | |
| 34 | -const char* | |
| 35 | -QEXC::Base::what() const throw() | |
| 36 | -{ | |
| 37 | - // Since unparse() returns a const string reference, its | |
| 38 | - // implementors must arrange to have it return a reference to a | |
| 39 | - // string that is not going to disappear. It is therefore safe | |
| 40 | - // for us to return it's c_str() pointer. | |
| 41 | - return this->unparse().c_str(); | |
| 42 | -} | |
| 43 | - | |
| 44 | -DLL_EXPORT | |
| 45 | -QEXC::General::General() | |
| 46 | -{ | |
| 47 | - // nothing needed | |
| 48 | -} | |
| 49 | - | |
| 50 | -DLL_EXPORT | |
| 51 | -QEXC::General::General(std::string const& message) : | |
| 52 | - Base(message) | |
| 53 | -{ | |
| 54 | - // nothing needed | |
| 55 | -} | |
| 56 | - | |
| 57 | -DLL_EXPORT | |
| 58 | -QEXC::System::System(std::string const& prefix, int sys_errno) | |
| 59 | -{ | |
| 60 | - // Note: using sys_errno in case errno is a macro. | |
| 61 | - this->sys_errno = sys_errno; | |
| 62 | - this->setMessage(prefix + ": " + strerror(sys_errno)); | |
| 63 | -} | |
| 64 | - | |
| 65 | -DLL_EXPORT | |
| 66 | -int | |
| 67 | -QEXC::System::getErrno() const | |
| 68 | -{ | |
| 69 | - return this->sys_errno; | |
| 70 | -} | |
| 71 | - | |
| 72 | -DLL_EXPORT | |
| 73 | -QEXC::Internal::Internal(std::string const& message) : | |
| 74 | - Base("INTERNAL ERROR: " + message) | |
| 75 | -{ | |
| 76 | - // nothing needed | |
| 77 | -} |
libqpdf/QPDF.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/QPDF.hh> |
| 3 | 2 | |
| 4 | 3 | #include <vector> |
| ... | ... | @@ -197,7 +196,8 @@ QPDF::BufferInputSource::seek(off_t offset, int whence) |
| 197 | 196 | break; |
| 198 | 197 | |
| 199 | 198 | default: |
| 200 | - throw QEXC::Internal("invalid argument to BufferInputSource::seek"); | |
| 199 | + throw std::logic_error( | |
| 200 | + "INTERNAL ERROR: invalid argument to BufferInputSource::seek"); | |
| 201 | 201 | break; |
| 202 | 202 | } |
| 203 | 203 | } |
| ... | ... | @@ -392,7 +392,7 @@ QPDF::parse() |
| 392 | 392 | void |
| 393 | 393 | QPDF::warn(QPDFExc const& e) |
| 394 | 394 | { |
| 395 | - this->warnings.push_back(e.unparse()); | |
| 395 | + this->warnings.push_back(e.what()); | |
| 396 | 396 | if (! this->suppress_warnings) |
| 397 | 397 | { |
| 398 | 398 | std::cerr << "WARNING: " << this->warnings.back() << std::endl; |
| ... | ... | @@ -956,8 +956,8 @@ QPDF::showXRefTable() |
| 956 | 956 | break; |
| 957 | 957 | |
| 958 | 958 | default: |
| 959 | - throw QEXC::Internal("unknown cross-reference table type while" | |
| 960 | - " showing xref_table"); | |
| 959 | + throw std::logic_error("unknown cross-reference table type while" | |
| 960 | + " showing xref_table"); | |
| 961 | 961 | break; |
| 962 | 962 | } |
| 963 | 963 | std::cout << std::endl; |
| ... | ... | @@ -988,7 +988,8 @@ QPDF::readObjectInternal(InputSource* input, |
| 988 | 988 | // Although dictionaries and arrays arbitrarily nest, these |
| 989 | 989 | // variables indicate what is at the top of the stack right |
| 990 | 990 | // now, so they can, by definition, never both be true. |
| 991 | - throw QEXC::Internal("readObjectInternal: in_dict && in_array"); | |
| 991 | + throw std::logic_error( | |
| 992 | + "INTERNAL ERROR: readObjectInternal: in_dict && in_array"); | |
| 992 | 993 | } |
| 993 | 994 | |
| 994 | 995 | QPDFObjectHandle object; |
| ... | ... | @@ -1121,9 +1122,10 @@ QPDF::readObjectInternal(InputSource* input, |
| 1121 | 1122 | } |
| 1122 | 1123 | else if (! object.isInitialized()) |
| 1123 | 1124 | { |
| 1124 | - throw QEXC::Internal(std::string("uninitialized object (token = ") + | |
| 1125 | - QUtil::int_to_string(token.getType()) + | |
| 1126 | - ", " + token.getValue() + ")"); | |
| 1125 | + throw std::logic_error( | |
| 1126 | + "INTERNAL ERROR: uninitialized object (token = " + | |
| 1127 | + QUtil::int_to_string(token.getType()) + | |
| 1128 | + ", " + token.getValue() + ")"); | |
| 1127 | 1129 | } |
| 1128 | 1130 | else |
| 1129 | 1131 | { |
| ... | ... | @@ -1846,13 +1848,13 @@ QPDF::pipeStreamData(int objid, int generation, |
| 1846 | 1848 | pipeline->write((unsigned char*)buf, len); |
| 1847 | 1849 | } |
| 1848 | 1850 | } |
| 1849 | - catch (QEXC::General& e) | |
| 1851 | + catch (std::runtime_error& e) | |
| 1850 | 1852 | { |
| 1851 | 1853 | QTC::TC("qpdf", "QPDF decoding error warning"); |
| 1852 | 1854 | warn(QPDFExc(this->file.getName(), this->file.getLastOffset(), |
| 1853 | 1855 | "error decoding stream data for object " + |
| 1854 | 1856 | QUtil::int_to_string(objid) + " " + |
| 1855 | - QUtil::int_to_string(generation) + ": " + e.unparse())); | |
| 1857 | + QUtil::int_to_string(generation) + ": " + e.what())); | |
| 1856 | 1858 | } |
| 1857 | 1859 | pipeline->finish(); |
| 1858 | 1860 | } | ... | ... |
libqpdf/QPDFExc.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/QPDFExc.hh> |
| 3 | - | |
| 4 | 2 | #include <qpdf/QUtil.hh> |
| 5 | 3 | |
| 6 | 4 | DLL_EXPORT |
| 7 | 5 | QPDFExc::QPDFExc(std::string const& message) : |
| 8 | - QEXC::General(message) | |
| 6 | + std::runtime_error(message) | |
| 9 | 7 | { |
| 10 | 8 | } |
| 11 | 9 | |
| 12 | 10 | DLL_EXPORT |
| 13 | 11 | QPDFExc::QPDFExc(std::string const& filename, int offset, |
| 14 | 12 | std::string const& message) : |
| 15 | - QEXC::General(filename + ": offset " + QUtil::int_to_string(offset) + | |
| 16 | - ": " + message) | |
| 13 | + std::runtime_error(filename + ": offset " + QUtil::int_to_string(offset) + | |
| 14 | + ": " + message) | |
| 17 | 15 | { |
| 18 | 16 | } |
| 19 | 17 | ... | ... |
libqpdf/QPDFObject.cc
libqpdf/QPDFObjectHandle.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/QPDFObjectHandle.hh> |
| 3 | 2 | |
| 4 | 3 | #include <qpdf/QPDF.hh> |
| ... | ... | @@ -13,9 +12,9 @@ |
| 13 | 12 | #include <qpdf/QPDF_Stream.hh> |
| 14 | 13 | |
| 15 | 14 | #include <qpdf/QTC.hh> |
| 16 | -#include <qpdf/QEXC.hh> | |
| 17 | 15 | #include <qpdf/QUtil.hh> |
| 18 | 16 | |
| 17 | +#include <stdexcept> | |
| 19 | 18 | #include <stdlib.h> |
| 20 | 19 | |
| 21 | 20 | DLL_EXPORT |
| ... | ... | @@ -114,7 +113,7 @@ QPDFObjectHandle::getNumericValue() |
| 114 | 113 | } |
| 115 | 114 | else |
| 116 | 115 | { |
| 117 | - throw QEXC::Internal("getNumericValue called for non-numeric object"); | |
| 116 | + throw std::logic_error("getNumericValue called for non-numeric object"); | |
| 118 | 117 | } |
| 119 | 118 | return result; |
| 120 | 119 | } |
| ... | ... | @@ -416,9 +415,10 @@ QPDFObjectHandle::getPageContents() |
| 416 | 415 | } |
| 417 | 416 | else |
| 418 | 417 | { |
| 419 | - throw QEXC::General("unknown item type while inspecting " | |
| 420 | - "element of /Contents array in page " | |
| 421 | - "dictionary"); | |
| 418 | + throw std::runtime_error( | |
| 419 | + "unknown item type while inspecting " | |
| 420 | + "element of /Contents array in page " | |
| 421 | + "dictionary"); | |
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | } |
| ... | ... | @@ -428,8 +428,8 @@ QPDFObjectHandle::getPageContents() |
| 428 | 428 | } |
| 429 | 429 | else |
| 430 | 430 | { |
| 431 | - throw QEXC::General("unknown object type inspecting /Contents " | |
| 432 | - "key in page dictionary"); | |
| 431 | + throw std::runtime_error("unknown object type inspecting /Contents " | |
| 432 | + "key in page dictionary"); | |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | return result; |
| ... | ... | @@ -542,7 +542,8 @@ QPDFObjectHandle::makeDirectInternal(std::set<int>& visited) |
| 542 | 542 | if (isStream()) |
| 543 | 543 | { |
| 544 | 544 | QTC::TC("qpdf", "QPDFObjectHandle ERR clone stream"); |
| 545 | - throw QEXC::General("attempt to make a stream into a direct object"); | |
| 545 | + throw std::runtime_error( | |
| 546 | + "attempt to make a stream into a direct object"); | |
| 546 | 547 | } |
| 547 | 548 | |
| 548 | 549 | int cur_objid = this->objid; |
| ... | ... | @@ -551,8 +552,9 @@ QPDFObjectHandle::makeDirectInternal(std::set<int>& visited) |
| 551 | 552 | if (visited.count(cur_objid)) |
| 552 | 553 | { |
| 553 | 554 | QTC::TC("qpdf", "QPDFObjectHandle makeDirect loop"); |
| 554 | - throw QEXC::General("loop detected while converting object from " | |
| 555 | - "indirect to direct"); | |
| 555 | + throw std::runtime_error( | |
| 556 | + "loop detected while converting object from " | |
| 557 | + "indirect to direct"); | |
| 556 | 558 | } |
| 557 | 559 | visited.insert(cur_objid); |
| 558 | 560 | } |
| ... | ... | @@ -620,8 +622,8 @@ QPDFObjectHandle::makeDirectInternal(std::set<int>& visited) |
| 620 | 622 | } |
| 621 | 623 | else |
| 622 | 624 | { |
| 623 | - throw QEXC::Internal("QPDFObjectHandle::makeIndirect: " | |
| 624 | - "unknown object type"); | |
| 625 | + throw std::logic_error("QPDFObjectHandle::makeIndirect: " | |
| 626 | + "unknown object type"); | |
| 625 | 627 | } |
| 626 | 628 | |
| 627 | 629 | this->obj = new_obj; |
| ... | ... | @@ -644,8 +646,8 @@ QPDFObjectHandle::assertInitialized() const |
| 644 | 646 | { |
| 645 | 647 | if (! this->initialized) |
| 646 | 648 | { |
| 647 | - throw QEXC::Internal("operation attempted on uninitialized " | |
| 648 | - "QPDFObjectHandle"); | |
| 649 | + throw std::logic_error("operation attempted on uninitialized " | |
| 650 | + "QPDFObjectHandle"); | |
| 649 | 651 | } |
| 650 | 652 | } |
| 651 | 653 | |
| ... | ... | @@ -654,8 +656,8 @@ QPDFObjectHandle::assertType(char const* type_name, bool istype) |
| 654 | 656 | { |
| 655 | 657 | if (! istype) |
| 656 | 658 | { |
| 657 | - throw QEXC::Internal(std::string("operation for ") + type_name + | |
| 658 | - " object attempted on object of wrong type"); | |
| 659 | + throw std::logic_error(std::string("operation for ") + type_name + | |
| 660 | + " object attempted on object of wrong type"); | |
| 659 | 661 | } |
| 660 | 662 | } |
| 661 | 663 | |
| ... | ... | @@ -665,7 +667,7 @@ QPDFObjectHandle::assertPageObject() |
| 665 | 667 | if (! (this->isDictionary() && this->hasKey("/Type") && |
| 666 | 668 | (this->getKey("/Type").getName() == "/Page"))) |
| 667 | 669 | { |
| 668 | - throw QEXC::Internal("page operation called on non-Page object"); | |
| 670 | + throw std::logic_error("page operation called on non-Page object"); | |
| 669 | 671 | } |
| 670 | 672 | } |
| 671 | 673 | ... | ... |
libqpdf/QPDFTokenizer.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/QPDFTokenizer.hh> |
| 3 | 2 | |
| 4 | 3 | // DO NOT USE ctype -- it is locale dependent for some things, and |
| ... | ... | @@ -6,9 +5,9 @@ |
| 6 | 5 | // be used. |
| 7 | 6 | |
| 8 | 7 | #include <qpdf/PCRE.hh> |
| 9 | -#include <qpdf/QEXC.hh> | |
| 10 | 8 | #include <qpdf/QTC.hh> |
| 11 | 9 | |
| 10 | +#include <stdexcept> | |
| 12 | 11 | #include <string.h> |
| 13 | 12 | |
| 14 | 13 | // See note above about ctype. |
| ... | ... | @@ -55,8 +54,9 @@ QPDFTokenizer::presentCharacter(char ch) |
| 55 | 54 | |
| 56 | 55 | if (state == st_token_ready) |
| 57 | 56 | { |
| 58 | - throw QEXC::Internal("QPDF tokenizer presented character " | |
| 59 | - "while token is waiting"); | |
| 57 | + throw std::logic_error( | |
| 58 | + "INTERNAL ERROR: QPDF tokenizer presented character " | |
| 59 | + "while token is waiting"); | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | char orig_ch = ch; |
| ... | ... | @@ -237,8 +237,9 @@ QPDFTokenizer::presentCharacter(char ch) |
| 237 | 237 | // last_char_was_bs is set/cleared below as appropriate |
| 238 | 238 | if (bs_num_count) |
| 239 | 239 | { |
| 240 | - throw QEXC::Internal("QPDFTokenizer: bs_num_count != 0 " | |
| 241 | - "when ch == '\\'"); | |
| 240 | + throw std::logic_error( | |
| 241 | + "INTERNAL ERROR: QPDFTokenizer: bs_num_count != 0 " | |
| 242 | + "when ch == '\\'"); | |
| 242 | 243 | } |
| 243 | 244 | } |
| 244 | 245 | else if (ch == '(') |
| ... | ... | @@ -333,7 +334,8 @@ QPDFTokenizer::presentCharacter(char ch) |
| 333 | 334 | } |
| 334 | 335 | else |
| 335 | 336 | { |
| 336 | - throw QEXC::Internal("invalid state while reading token"); | |
| 337 | + throw std::logic_error( | |
| 338 | + "INTERNAL ERROR: invalid state while reading token"); | |
| 337 | 339 | } |
| 338 | 340 | |
| 339 | 341 | if ((state == st_token_ready) && (type == tt_word)) | ... | ... |
libqpdf/QPDFWriter.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/QPDFWriter.hh> |
| 3 | 2 | |
| 4 | 3 | #include <assert.h> |
| ... | ... | @@ -479,8 +478,8 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) |
| 479 | 478 | } |
| 480 | 479 | else if (object.isScalar()) |
| 481 | 480 | { |
| 482 | - throw QEXC::Internal( | |
| 483 | - "QPDFWriter::enqueueObject: indirect scalar: " + | |
| 481 | + throw std::logic_error( | |
| 482 | + "INTERNAL ERROR: QPDFWriter::enqueueObject: indirect scalar: " + | |
| 484 | 483 | std::string(this->filename) + " " + |
| 485 | 484 | QUtil::int_to_string(object.getObjectID()) + " " + |
| 486 | 485 | QUtil::int_to_string(object.getGeneration())); |
| ... | ... | @@ -559,8 +558,8 @@ QPDFWriter::unparseChild(QPDFObjectHandle child, int level, int flags) |
| 559 | 558 | { |
| 560 | 559 | if (child.isScalar()) |
| 561 | 560 | { |
| 562 | - throw QEXC::Internal( | |
| 563 | - "QPDFWriter::unparseChild: indirect scalar: " + | |
| 561 | + throw std::logic_error( | |
| 562 | + "INTERNAL ERROR: QPDFWriter::unparseChild: indirect scalar: " + | |
| 564 | 563 | QUtil::int_to_string(child.getObjectID()) + " " + |
| 565 | 564 | QUtil::int_to_string(child.getGeneration())); |
| 566 | 565 | } |
| ... | ... | @@ -1599,7 +1598,7 @@ QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset, |
| 1599 | 1598 | break; |
| 1600 | 1599 | |
| 1601 | 1600 | default: |
| 1602 | - throw QEXC::Internal("invalid type writing xref stream"); | |
| 1601 | + throw std::logic_error("invalid type writing xref stream"); | |
| 1603 | 1602 | break; |
| 1604 | 1603 | } |
| 1605 | 1604 | } | ... | ... |
libqpdf/QPDFXRefEntry.cc
libqpdf/QPDF_Array.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/QPDF_Array.hh> |
| 3 | - | |
| 4 | -#include <qpdf/QEXC.hh> | |
| 2 | +#include <stdexcept> | |
| 5 | 3 | |
| 6 | 4 | QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& items) : |
| 7 | 5 | items(items) |
| ... | ... | @@ -37,7 +35,8 @@ QPDF_Array::getItem(int n) const |
| 37 | 35 | { |
| 38 | 36 | if ((n < 0) || (n >= (int)this->items.size())) |
| 39 | 37 | { |
| 40 | - throw QEXC::Internal("bounds array accessing QPDF_Array element"); | |
| 38 | + throw std::logic_error( | |
| 39 | + "INTERNAL ERROR: bounds array accessing QPDF_Array element"); | |
| 41 | 40 | } |
| 42 | 41 | return this->items[n]; |
| 43 | 42 | } | ... | ... |
libqpdf/QPDF_Bool.cc
libqpdf/QPDF_Dictionary.cc
libqpdf/QPDF_Integer.cc
libqpdf/QPDF_Name.cc
libqpdf/QPDF_Null.cc
libqpdf/QPDF_Real.cc
libqpdf/QPDF_Stream.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/QPDF_Stream.hh> |
| 3 | 2 | |
| 4 | -#include <qpdf/QEXC.hh> | |
| 5 | 3 | #include <qpdf/QUtil.hh> |
| 6 | 4 | #include <qpdf/Pipeline.hh> |
| 7 | 5 | #include <qpdf/Pl_Flate.hh> |
| ... | ... | @@ -17,6 +15,8 @@ |
| 17 | 15 | #include <qpdf/QPDFExc.hh> |
| 18 | 16 | #include <qpdf/Pl_QPDFTokenizer.hh> |
| 19 | 17 | |
| 18 | +#include <stdexcept> | |
| 19 | + | |
| 20 | 20 | QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation, |
| 21 | 21 | QPDFObjectHandle stream_dict, |
| 22 | 22 | off_t offset, int length) : |
| ... | ... | @@ -29,8 +29,9 @@ QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation, |
| 29 | 29 | { |
| 30 | 30 | if (! stream_dict.isDictionary()) |
| 31 | 31 | { |
| 32 | - throw QEXC::Internal("stream object instantiated with non-dictionary " | |
| 33 | - "object for dictionary"); | |
| 32 | + throw std::logic_error( | |
| 33 | + "stream object instantiated with non-dictionary " | |
| 34 | + "object for dictionary"); | |
| 34 | 35 | } |
| 35 | 36 | } |
| 36 | 37 | |
| ... | ... | @@ -298,8 +299,9 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter, |
| 298 | 299 | } |
| 299 | 300 | else |
| 300 | 301 | { |
| 301 | - throw QEXC::Internal("QPDFStream: unknown filter " | |
| 302 | - "encountered after check"); | |
| 302 | + throw std::logic_error( | |
| 303 | + "INTERNAL ERROR: QPDFStream: unknown filter " | |
| 304 | + "encountered after check"); | |
| 303 | 305 | } |
| 304 | 306 | } |
| 305 | 307 | } | ... | ... |
libqpdf/QPDF_String.cc
libqpdf/QPDF_encryption.cc
| ... | ... | @@ -386,7 +386,8 @@ QPDF::getKeyForObject(int objid, int generation) |
| 386 | 386 | { |
| 387 | 387 | if (! this->encrypted) |
| 388 | 388 | { |
| 389 | - throw QEXC::Internal("request for encryption key in non-encrypted PDF"); | |
| 389 | + throw std::logic_error( | |
| 390 | + "request for encryption key in non-encrypted PDF"); | |
| 390 | 391 | } |
| 391 | 392 | |
| 392 | 393 | if (! ((objid == this->cached_key_objid) && | ... | ... |
libqpdf/QPDF_linearization.cc
| ... | ... | @@ -1177,8 +1177,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) |
| 1177 | 1177 | { |
| 1178 | 1178 | // Note that we can't call optimize here because we don't know |
| 1179 | 1179 | // whether it should be called with or without allow changes. |
| 1180 | - throw QEXC::Internal("QPDF::calculateLinearizationData " | |
| 1181 | - "called before optimize()"); | |
| 1180 | + throw std::logic_error( | |
| 1181 | + "INTERNAL ERROR: QPDF::calculateLinearizationData " | |
| 1182 | + "called before optimize()"); | |
| 1182 | 1183 | } |
| 1183 | 1184 | |
| 1184 | 1185 | // Separate objects into the categories sufficient for us to |
| ... | ... | @@ -1336,8 +1337,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) |
| 1336 | 1337 | break; |
| 1337 | 1338 | |
| 1338 | 1339 | case ObjUser::ou_bad: |
| 1339 | - throw QEXC::Internal("QPDF::calculateLinearizationData: " | |
| 1340 | - "invalid user type"); | |
| 1340 | + throw std::logic_error( | |
| 1341 | + "INTERNAL ERROR: QPDF::calculateLinearizationData: " | |
| 1342 | + "invalid user type"); | |
| 1341 | 1343 | break; |
| 1342 | 1344 | } |
| 1343 | 1345 | } |
| ... | ... | @@ -1444,8 +1446,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) |
| 1444 | 1446 | ObjGen first_page_og(pages[0].getObjectID(), pages[0].getGeneration()); |
| 1445 | 1447 | if (! lc_first_page_private.count(first_page_og)) |
| 1446 | 1448 | { |
| 1447 | - throw QEXC::Internal("QPDF::calculateLinearizationData: first page " | |
| 1448 | - "object not in lc_first_page_private"); | |
| 1449 | + throw std::logic_error( | |
| 1450 | + "INTERNAL ERROR: QPDF::calculateLinearizationData: first page " | |
| 1451 | + "object not in lc_first_page_private"); | |
| 1449 | 1452 | } |
| 1450 | 1453 | lc_first_page_private.erase(first_page_og); |
| 1451 | 1454 | this->c_linp.first_page_object = pages[0].getObjectID(); |
| ... | ... | @@ -1492,7 +1495,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) |
| 1492 | 1495 | ObjGen page_og(pages[i].getObjectID(), pages[i].getGeneration()); |
| 1493 | 1496 | if (! lc_other_page_private.count(page_og)) |
| 1494 | 1497 | { |
| 1495 | - throw QEXC::Internal( | |
| 1498 | + throw std::logic_error( | |
| 1499 | + "INTERNAL ERROR: " | |
| 1496 | 1500 | "QPDF::calculateLinearizationData: page object for page " + |
| 1497 | 1501 | QUtil::int_to_string(i) + " not in lc_other_page_private"); |
| 1498 | 1502 | } |
| ... | ... | @@ -1522,8 +1526,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) |
| 1522 | 1526 | // That should have covered all part7 objects. |
| 1523 | 1527 | if (! lc_other_page_private.empty()) |
| 1524 | 1528 | { |
| 1525 | - throw QEXC::Internal( | |
| 1526 | - "QPDF::calculateLinearizationData: lc_other_page_private is " | |
| 1529 | + throw std::logic_error( | |
| 1530 | + "INTERNAL ERROR:" | |
| 1531 | + " QPDF::calculateLinearizationData: lc_other_page_private is " | |
| 1527 | 1532 | "not empty after generation of part7"); |
| 1528 | 1533 | } |
| 1529 | 1534 | |
| ... | ... | @@ -1601,7 +1606,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) |
| 1601 | 1606 | } |
| 1602 | 1607 | if (! lc_thumbnail_private.empty()) |
| 1603 | 1608 | { |
| 1604 | - throw QEXC::Internal( | |
| 1609 | + throw std::logic_error( | |
| 1610 | + "INTERNAL ERROR: " | |
| 1605 | 1611 | "QPDF::calculateLinearizationData: lc_thumbnail_private " |
| 1606 | 1612 | "not empty after placing thumbnails"); |
| 1607 | 1613 | } |
| ... | ... | @@ -1633,11 +1639,12 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) |
| 1633 | 1639 | unsigned int num_wanted = this->object_to_obj_users.size(); |
| 1634 | 1640 | if (num_placed != num_wanted) |
| 1635 | 1641 | { |
| 1636 | - throw QEXC::Internal("QPDF::calculateLinearizationData: wrong " | |
| 1637 | - "number of objects placed (num_placed = " + | |
| 1638 | - QUtil::int_to_string(num_placed) + | |
| 1639 | - "; number of objects: " + | |
| 1640 | - QUtil::int_to_string(num_wanted)); | |
| 1642 | + throw std::logic_error( | |
| 1643 | + "INTERNAL ERROR: QPDF::calculateLinearizationData: wrong " | |
| 1644 | + "number of objects placed (num_placed = " + | |
| 1645 | + QUtil::int_to_string(num_placed) + | |
| 1646 | + "; number of objects: " + | |
| 1647 | + QUtil::int_to_string(num_wanted)); | |
| 1641 | 1648 | } |
| 1642 | 1649 | |
| 1643 | 1650 | // Calculate shared object hint table information including | ... | ... |
libqpdf/QPDF_optimization.cc
| ... | ... | @@ -78,8 +78,9 @@ QPDF::flattenScalarReferences() |
| 78 | 78 | { |
| 79 | 79 | if (node.isScalar()) |
| 80 | 80 | { |
| 81 | - throw QEXC::Internal( | |
| 82 | - "flattenScalarReferences landed at indirect scalar"); | |
| 81 | + throw std::logic_error( | |
| 82 | + "INTERNAL ERROR:" | |
| 83 | + " flattenScalarReferences landed at indirect scalar"); | |
| 83 | 84 | } |
| 84 | 85 | ObjGen og(node.getObjectID(), node.getGeneration()); |
| 85 | 86 | if (visited.count(og) > 0) |
| ... | ... | @@ -124,7 +125,8 @@ QPDF::flattenScalarReferences() |
| 124 | 125 | { |
| 125 | 126 | // QPDF_Dictionary.getKeys() never returns null |
| 126 | 127 | // keys. |
| 127 | - throw QEXC::Internal("dictionary with null key found"); | |
| 128 | + throw std::logic_error( | |
| 129 | + "INTERNAL ERROR: dictionary with null key found"); | |
| 128 | 130 | } |
| 129 | 131 | else if (oh.isScalar()) |
| 130 | 132 | { | ... | ... |
libqpdf/QUtil.cc
| 1 | - | |
| 1 | +#include <qpdf/DLL.hh> | |
| 2 | 2 | #include <qpdf/QUtil.hh> |
| 3 | 3 | #include <stdio.h> |
| 4 | 4 | #include <errno.h> |
| ... | ... | @@ -25,9 +25,9 @@ QUtil::int_to_string(int num, int fullpad) |
| 25 | 25 | // -2 or -1 to leave space for the possible negative sign and for NUL... |
| 26 | 26 | if (abs(fullpad) > (int)sizeof(t) - ((num < 0)?2:1)) |
| 27 | 27 | { |
| 28 | - throw QEXC::Internal("Util::int_to_string has been called with " | |
| 29 | - "a padding value greater than its internal " | |
| 30 | - "limit"); | |
| 28 | + throw std::logic_error("Util::int_to_string has been called with " | |
| 29 | + "a padding value greater than its internal " | |
| 30 | + "limit"); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | if (fullpad) |
| ... | ... | @@ -62,9 +62,9 @@ QUtil::double_to_string(double num, int decimal_places) |
| 62 | 62 | // always pass in those cases. |
| 63 | 63 | if (decimal_places + 1 + (int)lhs.length() > (int)sizeof(t) - 1) |
| 64 | 64 | { |
| 65 | - throw QEXC::Internal("Util::double_to_string has been called with " | |
| 66 | - "a number and a decimal places specification " | |
| 67 | - "that would break an internal limit"); | |
| 65 | + throw std::logic_error("Util::double_to_string has been called with " | |
| 66 | + "a number and a decimal places specification " | |
| 67 | + "that would break an internal limit"); | |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | if (decimal_places) |
| ... | ... | @@ -79,23 +79,30 @@ QUtil::double_to_string(double num, int decimal_places) |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | DLL_EXPORT |
| 82 | +void | |
| 83 | +QUtil::throw_system_error(std::string const& description) | |
| 84 | +{ | |
| 85 | + throw std::runtime_error(description + ": " + strerror(errno)); | |
| 86 | +} | |
| 87 | + | |
| 88 | +DLL_EXPORT | |
| 82 | 89 | int |
| 83 | -QUtil::os_wrapper(std::string const& description, int status) throw (QEXC::System) | |
| 90 | +QUtil::os_wrapper(std::string const& description, int status) | |
| 84 | 91 | { |
| 85 | 92 | if (status == -1) |
| 86 | 93 | { |
| 87 | - throw QEXC::System(description, errno); | |
| 94 | + throw_system_error(description); | |
| 88 | 95 | } |
| 89 | 96 | return status; |
| 90 | 97 | } |
| 91 | 98 | |
| 92 | 99 | DLL_EXPORT |
| 93 | 100 | FILE* |
| 94 | -QUtil::fopen_wrapper(std::string const& description, FILE* f) throw (QEXC::System) | |
| 101 | +QUtil::fopen_wrapper(std::string const& description, FILE* f) | |
| 95 | 102 | { |
| 96 | 103 | if (f == 0) |
| 97 | 104 | { |
| 98 | - throw QEXC::System(description, errno); | |
| 105 | + throw_system_error(description); | |
| 99 | 106 | } |
| 100 | 107 | return f; |
| 101 | 108 | } |
| ... | ... | @@ -240,7 +247,7 @@ QUtil::toUTF8(unsigned long uval) |
| 240 | 247 | |
| 241 | 248 | if (uval > 0x7fffffff) |
| 242 | 249 | { |
| 243 | - throw QEXC::General("bounds error in QUtil::toUTF8"); | |
| 250 | + throw std::runtime_error("bounds error in QUtil::toUTF8"); | |
| 244 | 251 | } |
| 245 | 252 | else if (uval < 128) |
| 246 | 253 | { |
| ... | ... | @@ -267,7 +274,7 @@ QUtil::toUTF8(unsigned long uval) |
| 267 | 274 | --cur_byte; |
| 268 | 275 | if (cur_byte < bytes) |
| 269 | 276 | { |
| 270 | - throw QEXC::Internal("QUtil::toUTF8: overflow error"); | |
| 277 | + throw std::logic_error("QUtil::toUTF8: overflow error"); | |
| 271 | 278 | } |
| 272 | 279 | } |
| 273 | 280 | // If maxval is k bits long, the high (7 - k) bits of the | ... | ... |
libqpdf/RC4.cc
libqpdf/bits.icc
| ... | ... | @@ -3,8 +3,8 @@ |
| 3 | 3 | #define __BITS_CC__ |
| 4 | 4 | |
| 5 | 5 | #include <algorithm> |
| 6 | +#include <stdexcept> | |
| 6 | 7 | #include <qpdf/QTC.hh> |
| 7 | -#include <qpdf/QEXC.hh> | |
| 8 | 8 | #include <qpdf/Pipeline.hh> |
| 9 | 9 | |
| 10 | 10 | // These functions may be run at places where the function call |
| ... | ... | @@ -28,11 +28,11 @@ read_bits(unsigned char const*& p, unsigned int& bit_offset, |
| 28 | 28 | |
| 29 | 29 | if (bits_wanted > bits_available) |
| 30 | 30 | { |
| 31 | - throw QEXC::General("overflow reading bit stream"); | |
| 31 | + throw std::length_error("overflow reading bit stream"); | |
| 32 | 32 | } |
| 33 | 33 | if (bits_wanted > 32) |
| 34 | 34 | { |
| 35 | - throw QEXC::Internal("read_bits: too many bits requested"); | |
| 35 | + throw std::out_of_range("read_bits: too many bits requested"); | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | unsigned long result = 0; |
| ... | ... | @@ -99,7 +99,7 @@ write_bits(unsigned char& ch, unsigned int& bit_offset, |
| 99 | 99 | { |
| 100 | 100 | if (bits > 32) |
| 101 | 101 | { |
| 102 | - throw QEXC::Internal("write_bits: too many bits requested"); | |
| 102 | + throw std::out_of_range("write_bits: too many bits requested"); | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // bit_offset + 1 is the number of bits left in ch | ... | ... |
libqpdf/build.mk
| ... | ... | @@ -22,7 +22,6 @@ SRCS_libqpdf = \ |
| 22 | 22 | libqpdf/Pl_QPDFTokenizer.cc \ |
| 23 | 23 | libqpdf/Pl_RC4.cc \ |
| 24 | 24 | libqpdf/Pl_StdioFile.cc \ |
| 25 | - libqpdf/QEXC.cc \ | |
| 26 | 25 | libqpdf/QPDF.cc \ |
| 27 | 26 | libqpdf/QPDFExc.cc \ |
| 28 | 27 | libqpdf/QPDFObject.cc \ |
| ... | ... | @@ -69,5 +68,5 @@ $(OBJS_libqpdf): libqpdf/$(OUTPUT_DIR)/%.lo: libqpdf/%.cc |
| 69 | 68 | # * Otherwise, increment REVISION |
| 70 | 69 | |
| 71 | 70 | libqpdf/$(OUTPUT_DIR)/libqpdf.la: $(OBJS_libqpdf) |
| 72 | - $(call makelib,$(OBJS_libqpdf),$@,2,1,1) | |
| 71 | + $(call makelib,$(OBJS_libqpdf),$@,3,0,0) | |
| 73 | 72 | ... | ... |
libqpdf/qpdf/MD5.hh
| 1 | - | |
| 2 | 1 | #ifndef __MD5_HH__ |
| 3 | 2 | #define __MD5_HH__ |
| 4 | 3 | |
| 5 | 4 | #include <string> |
| 6 | 5 | #include <qpdf/DLL.hh> |
| 7 | -#include <qpdf/QEXC.hh> | |
| 8 | 6 | #include <qpdf/qpdf-config.h> |
| 9 | 7 | #ifdef HAVE_INTTYPES_H |
| 10 | 8 | # include <inttypes.h> |
| ... | ... | @@ -26,8 +24,7 @@ class MD5 |
| 26 | 24 | |
| 27 | 25 | // encodes file and finalizes |
| 28 | 26 | DLL_EXPORT |
| 29 | - void encodeFile(char const* filename, int up_to_size = -1) | |
| 30 | - throw(QEXC::System); | |
| 27 | + void encodeFile(char const* filename, int up_to_size = -1); | |
| 31 | 28 | |
| 32 | 29 | // appends string to current md5 object |
| 33 | 30 | DLL_EXPORT | ... | ... |
libqpdf/qpdf/PCRE.hh
| ... | ... | @@ -10,9 +10,9 @@ |
| 10 | 10 | #endif |
| 11 | 11 | #include <pcre.h> |
| 12 | 12 | #include <string> |
| 13 | +#include <stdexcept> | |
| 13 | 14 | |
| 14 | 15 | #include <qpdf/DLL.hh> |
| 15 | -#include <qpdf/QEXC.hh> | |
| 16 | 16 | |
| 17 | 17 | // Note: this class does not encapsulate all features of the PCRE |
| 18 | 18 | // package -- only those that I actually need right now are here. |
| ... | ... | @@ -20,18 +20,9 @@ |
| 20 | 20 | class PCRE |
| 21 | 21 | { |
| 22 | 22 | public: |
| 23 | - class Exception: public QEXC::General | |
| 24 | - { | |
| 25 | - public: | |
| 26 | - DLL_EXPORT | |
| 27 | - Exception(std::string const& message); | |
| 28 | - DLL_EXPORT | |
| 29 | - virtual ~Exception() throw() {} | |
| 30 | - }; | |
| 31 | - | |
| 32 | 23 | // This is thrown when an attempt is made to access a non-existent |
| 33 | 24 | // back reference. |
| 34 | - class NoBackref: public Exception | |
| 25 | + class NoBackref: public std::logic_error | |
| 35 | 26 | { |
| 36 | 27 | public: |
| 37 | 28 | DLL_EXPORT |
| ... | ... | @@ -65,14 +56,13 @@ class PCRE |
| 65 | 56 | |
| 66 | 57 | // see getMatch flags below |
| 67 | 58 | DLL_EXPORT |
| 68 | - std::string getMatch(int n, int flags = 0) | |
| 69 | - throw(QEXC::General, Exception); | |
| 59 | + std::string getMatch(int n, int flags = 0); | |
| 70 | 60 | DLL_EXPORT |
| 71 | - void getOffsetLength(int n, int& offset, int& length) throw(Exception); | |
| 61 | + void getOffsetLength(int n, int& offset, int& length); | |
| 72 | 62 | DLL_EXPORT |
| 73 | - int getOffset(int n) throw(Exception); | |
| 63 | + int getOffset(int n); | |
| 74 | 64 | DLL_EXPORT |
| 75 | - int getLength(int n) throw(Exception); | |
| 65 | + int getLength(int n); | |
| 76 | 66 | |
| 77 | 67 | // nMatches returns the number of available matches including |
| 78 | 68 | // match 0 which is the whole string. In other words, if you |
| ... | ... | @@ -105,14 +95,13 @@ class PCRE |
| 105 | 95 | // The value passed in as options is passed to pcre_exec. See man |
| 106 | 96 | // pcreapi for details. |
| 107 | 97 | DLL_EXPORT |
| 108 | - PCRE(char const* pattern, int options = 0) throw(Exception); | |
| 98 | + PCRE(char const* pattern, int options = 0); | |
| 109 | 99 | DLL_EXPORT |
| 110 | 100 | ~PCRE(); |
| 111 | 101 | |
| 112 | 102 | DLL_EXPORT |
| 113 | 103 | Match match(char const* subject, int options = 0, int startoffset = 0, |
| 114 | - int size = -1) | |
| 115 | - throw(QEXC::General, Exception); | |
| 104 | + int size = -1); | |
| 116 | 105 | |
| 117 | 106 | DLL_EXPORT |
| 118 | 107 | static void test(int n = 0); | ... | ... |
libqpdf/qpdf/Pl_ASCII85Decoder.hh
libqpdf/qpdf/Pl_ASCIIHexDecoder.hh
libqpdf/qpdf/Pl_LZWDecoder.hh
libqpdf/qpdf/Pl_MD5.hh
libqpdf/qpdf/Pl_PNGFilter.hh
| ... | ... | @@ -19,21 +19,6 @@ |
| 19 | 19 | class Pl_PNGFilter: public Pipeline |
| 20 | 20 | { |
| 21 | 21 | public: |
| 22 | - class Exception: public Pipeline::Exception | |
| 23 | - { | |
| 24 | - public: | |
| 25 | - DLL_EXPORT | |
| 26 | - Exception(std::string const& message) : | |
| 27 | - Pipeline::Exception(message) | |
| 28 | - { | |
| 29 | - } | |
| 30 | - | |
| 31 | - DLL_EXPORT | |
| 32 | - virtual ~Exception() throw () | |
| 33 | - { | |
| 34 | - } | |
| 35 | - }; | |
| 36 | - | |
| 37 | 22 | // Encoding is not presently supported |
| 38 | 23 | enum action_e { a_encode, a_decode }; |
| 39 | 24 | ... | ... |
libqpdf/qpdf/Pl_QPDFTokenizer.hh
libqpdf/qpdf/Pl_RC4.hh
| 1 | - | |
| 2 | 1 | #ifndef __PL_RC4_HH__ |
| 3 | 2 | #define __PL_RC4_HH__ |
| 4 | 3 | |
| ... | ... | @@ -9,21 +8,6 @@ |
| 9 | 8 | class Pl_RC4: public Pipeline |
| 10 | 9 | { |
| 11 | 10 | public: |
| 12 | - class Exception: public Pipeline::Exception | |
| 13 | - { | |
| 14 | - public: | |
| 15 | - DLL_EXPORT | |
| 16 | - Exception(std::string const& message) : | |
| 17 | - Pipeline::Exception(message) | |
| 18 | - { | |
| 19 | - } | |
| 20 | - | |
| 21 | - DLL_EXPORT | |
| 22 | - virtual ~Exception() throw() | |
| 23 | - { | |
| 24 | - } | |
| 25 | - }; | |
| 26 | - | |
| 27 | 11 | static int const def_bufsize = 65536; |
| 28 | 12 | |
| 29 | 13 | // key_len of -1 means treat key_data as a null-terminated string | ... | ... |
libqpdf/qpdf/QPDF_Array.hh
libqpdf/qpdf/QPDF_Bool.hh
libqpdf/qpdf/QPDF_Dictionary.hh
libqpdf/qpdf/QPDF_Integer.hh
libqpdf/qpdf/QPDF_Name.hh
libqpdf/qpdf/QPDF_Null.hh
libqpdf/qpdf/QPDF_Real.hh
libqpdf/qpdf/QPDF_Stream.hh
libqpdf/qpdf/QPDF_String.hh
libqpdf/qpdf/RC4.hh
libtests/bits.cc
libtests/buffer.cc
libtests/build.mk
libtests/flate.cc
| ... | ... | @@ -105,9 +105,9 @@ int main(int argc, char* argv[]) |
| 105 | 105 | { |
| 106 | 106 | run(filename); |
| 107 | 107 | } |
| 108 | - catch (QEXC::General& e) | |
| 108 | + catch (std::exception& e) | |
| 109 | 109 | { |
| 110 | - std::cout << e.unparse() << std::endl; | |
| 110 | + std::cout << e.what() << std::endl; | |
| 111 | 111 | } |
| 112 | 112 | return 0; |
| 113 | 113 | } | ... | ... |
libtests/md5.cc
libtests/pcre.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/PCRE.hh> |
| 3 | 2 | #include <iostream> |
| 4 | 3 | #include <string.h> |
| ... | ... | @@ -12,7 +11,7 @@ int main(int argc, char* argv[]) |
| 12 | 11 | PCRE("^([\\p{L}]+)", PCRE_UTF8); |
| 13 | 12 | std::cout << "1" << std::endl; |
| 14 | 13 | } |
| 15 | - catch (PCRE::Exception& e) | |
| 14 | + catch (std::exception& e) | |
| 16 | 15 | { |
| 17 | 16 | std::cout << "0" << std::endl; |
| 18 | 17 | } | ... | ... |
libtests/png_filter.cc
| 1 | - | |
| 2 | 1 | #include <qpdf/Pl_PNGFilter.hh> |
| 3 | 2 | #include <qpdf/Pl_StdioFile.hh> |
| 4 | 3 | |
| ... | ... | @@ -79,9 +78,9 @@ int main(int argc, char* argv[]) |
| 79 | 78 | { |
| 80 | 79 | run(filename, encode, columns); |
| 81 | 80 | } |
| 82 | - catch (QEXC::General& e) | |
| 81 | + catch (std::exception& e) | |
| 83 | 82 | { |
| 84 | - std::cout << e.unparse() << std::endl; | |
| 83 | + std::cout << e.what() << std::endl; | |
| 85 | 84 | } |
| 86 | 85 | return 0; |
| 87 | 86 | } | ... | ... |
libtests/pointer_holder.cc
libtests/qexc.cc deleted
| 1 | - | |
| 2 | -#include <qpdf/QEXC.hh> | |
| 3 | -#include <iostream> | |
| 4 | -#include <errno.h> | |
| 5 | -#include <stdlib.h> | |
| 6 | - | |
| 7 | -void f(int n) | |
| 8 | -{ | |
| 9 | - switch (n) | |
| 10 | - { | |
| 11 | - case 0: | |
| 12 | - throw QEXC::General("general exception"); | |
| 13 | - break; | |
| 14 | - | |
| 15 | - case 1: | |
| 16 | - throw QEXC::Internal("internal error"); | |
| 17 | - break; | |
| 18 | - | |
| 19 | - case 2: | |
| 20 | - throw QEXC::System("doing something", EINVAL); | |
| 21 | - break; | |
| 22 | - } | |
| 23 | -} | |
| 24 | - | |
| 25 | -int main(int argc, char* argv[]) | |
| 26 | -{ | |
| 27 | - if (argc != 2) | |
| 28 | - { | |
| 29 | - std::cerr << "usage: qexc n" << std::endl; | |
| 30 | - exit(2); | |
| 31 | - } | |
| 32 | - | |
| 33 | - try | |
| 34 | - { | |
| 35 | - f(atoi(argv[1])); | |
| 36 | - } | |
| 37 | - catch (QEXC::General& e) | |
| 38 | - { | |
| 39 | - std::cerr << "exception: " << e.unparse() << std::endl; | |
| 40 | - std::cerr << "what: " << e.what() << std::endl; | |
| 41 | - exit(2); | |
| 42 | - } | |
| 43 | - catch (std::exception& e) | |
| 44 | - { | |
| 45 | - std::cerr << "uncaught exception: " << e.what() << std::endl; | |
| 46 | - exit(3); | |
| 47 | - } | |
| 48 | - catch (...) | |
| 49 | - { | |
| 50 | - exit(4); | |
| 51 | - } | |
| 52 | - return 0; | |
| 53 | -} |
libtests/qtest/buffer/buffer.out
libtests/qtest/qexc.test deleted
| 1 | -#!/usr/bin/env perl | |
| 2 | - | |
| 3 | -require 5.008; | |
| 4 | -BEGIN { $^W = 1; } | |
| 5 | -use strict; | |
| 6 | - | |
| 7 | -chdir("qexc") or die "chdir qexc failed: $!\n"; | |
| 8 | - | |
| 9 | -require TestDriver; | |
| 10 | - | |
| 11 | -my $td = new TestDriver('qexc'); | |
| 12 | - | |
| 13 | -my @tests = | |
| 14 | - (['general exception', 2], | |
| 15 | - ['internal error', 3], | |
| 16 | - ['system exception', 2], | |
| 17 | - ); | |
| 18 | - | |
| 19 | -for (my $i = 0; $i < scalar(@tests); ++$i) | |
| 20 | -{ | |
| 21 | - $td->runtest($tests[$i]->[0], | |
| 22 | - {$td->COMMAND => "qexc $i"}, | |
| 23 | - {$td->FILE => "test$i.out", | |
| 24 | - $td->EXIT_STATUS => $tests[$i]->[1]}, | |
| 25 | - $td->NORMALIZE_NEWLINES); | |
| 26 | -} | |
| 27 | - | |
| 28 | -$td->report(scalar(@tests)); |
libtests/qtest/qexc/test0.out deleted
libtests/qtest/qexc/test1.out deleted
| 1 | -uncaught exception: INTERNAL ERROR: internal error |
libtests/qtest/qexc/test2.out deleted
libtests/qtest/qutil/qutil.out
| ... | ... | @@ -4,11 +4,11 @@ |
| 4 | 4 | 3.141590 |
| 5 | 5 | 3.142 |
| 6 | 6 | 1000.123000 |
| 7 | -exception 1: INTERNAL ERROR: Util::int_to_string has been called with a padding value greater than its internal limit | |
| 8 | -exception 2: INTERNAL ERROR: Util::int_to_string has been called with a padding value greater than its internal limit | |
| 9 | -exception 3: INTERNAL ERROR: Util::int_to_string has been called with a padding value greater than its internal limit | |
| 10 | -exception 4: INTERNAL ERROR: Util::double_to_string has been called with a number and a decimal places specification that would break an internal limit | |
| 11 | -exception 5: INTERNAL ERROR: Util::double_to_string has been called with a number and a decimal places specification that would break an internal limit | |
| 7 | +exception 1: Util::int_to_string has been called with a padding value greater than its internal limit | |
| 8 | +exception 2: Util::int_to_string has been called with a padding value greater than its internal limit | |
| 9 | +exception 3: Util::int_to_string has been called with a padding value greater than its internal limit | |
| 10 | +exception 4: Util::double_to_string has been called with a number and a decimal places specification that would break an internal limit | |
| 11 | +exception 5: Util::double_to_string has been called with a number and a decimal places specification that would break an internal limit | |
| 12 | 12 | one |
| 13 | 13 | 7 |
| 14 | 14 | compare okay | ... | ... |
libtests/qutil.cc
| 1 | - | |
| 2 | 1 | #include <iostream> |
| 3 | 2 | #include <stdio.h> |
| 4 | 3 | #include <sys/types.h> |
| ... | ... | @@ -27,9 +26,9 @@ void string_conversion_test() |
| 27 | 26 | // int_to_string bounds error |
| 28 | 27 | std::cout << QUtil::int_to_string(1, 50) << std::endl; |
| 29 | 28 | } |
| 30 | - catch(QEXC::Internal &e) | |
| 29 | + catch (std::logic_error &e) | |
| 31 | 30 | { |
| 32 | - std::cout << "exception 1: " << e.unparse() << std::endl; | |
| 31 | + std::cout << "exception 1: " << e.what() << std::endl; | |
| 33 | 32 | } |
| 34 | 33 | |
| 35 | 34 | try |
| ... | ... | @@ -37,9 +36,9 @@ void string_conversion_test() |
| 37 | 36 | // QUtil::int_to_string bounds error |
| 38 | 37 | std::cout << QUtil::int_to_string(1, -50) << std::endl; |
| 39 | 38 | } |
| 40 | - catch(QEXC::Internal &e) | |
| 39 | + catch (std::logic_error& e) | |
| 41 | 40 | { |
| 42 | - std::cout << "exception 2: " << e.unparse() << std::endl; | |
| 41 | + std::cout << "exception 2: " << e.what() << std::endl; | |
| 43 | 42 | } |
| 44 | 43 | |
| 45 | 44 | try |
| ... | ... | @@ -47,9 +46,9 @@ void string_conversion_test() |
| 47 | 46 | // QUtil::int_to_string bounds error |
| 48 | 47 | std::cout << QUtil::int_to_string(-1, 49) << std::endl; |
| 49 | 48 | } |
| 50 | - catch(QEXC::Internal &e) | |
| 49 | + catch (std::logic_error& e) | |
| 51 | 50 | { |
| 52 | - std::cout << "exception 3: " << e.unparse() << std::endl; | |
| 51 | + std::cout << "exception 3: " << e.what() << std::endl; | |
| 53 | 52 | } |
| 54 | 53 | |
| 55 | 54 | |
| ... | ... | @@ -58,9 +57,9 @@ void string_conversion_test() |
| 58 | 57 | // QUtil::double_to_string bounds error |
| 59 | 58 | std::cout << QUtil::double_to_string(3.14159, 1024) << std::endl; |
| 60 | 59 | } |
| 61 | - catch(QEXC::Internal &e) | |
| 60 | + catch (std::logic_error& e) | |
| 62 | 61 | { |
| 63 | - std::cout << "exception 4: " << e.unparse() << std::endl; | |
| 62 | + std::cout << "exception 4: " << e.what() << std::endl; | |
| 64 | 63 | } |
| 65 | 64 | |
| 66 | 65 | try |
| ... | ... | @@ -68,9 +67,9 @@ void string_conversion_test() |
| 68 | 67 | // QUtil::double_to_string bounds error |
| 69 | 68 | std::cout << QUtil::double_to_string(1000.0, 95) << std::endl; |
| 70 | 69 | } |
| 71 | - catch(QEXC::Internal &e) | |
| 70 | + catch (std::logic_error& e) | |
| 72 | 71 | { |
| 73 | - std::cout << "exception 5: " << e.unparse() << std::endl; | |
| 72 | + std::cout << "exception 5: " << e.what() << std::endl; | |
| 74 | 73 | } |
| 75 | 74 | |
| 76 | 75 | std::string embedded_null = "one"; |
| ... | ... | @@ -101,9 +100,9 @@ void os_wrapper_test() |
| 101 | 100 | std::cout << "after open" << std::endl; |
| 102 | 101 | (void) close(fd); |
| 103 | 102 | } |
| 104 | - catch (QEXC::System& s) | |
| 103 | + catch (std::runtime_error& s) | |
| 105 | 104 | { |
| 106 | - std::cout << "exception: " << s.unparse() << std::endl; | |
| 105 | + std::cout << "exception: " << s.what() << std::endl; | |
| 107 | 106 | } |
| 108 | 107 | } |
| 109 | 108 | |
| ... | ... | @@ -118,9 +117,9 @@ void fopen_wrapper_test() |
| 118 | 117 | std::cout << "after fopen" << std::endl; |
| 119 | 118 | (void) fclose(f); |
| 120 | 119 | } |
| 121 | - catch (QEXC::System& s) | |
| 120 | + catch (std::runtime_error& s) | |
| 122 | 121 | { |
| 123 | - std::cout << "exception: " << s.unparse() << std::endl; | |
| 122 | + std::cout << "exception: " << s.what() << std::endl; | |
| 124 | 123 | } |
| 125 | 124 | } |
| 126 | 125 | |
| ... | ... | @@ -171,7 +170,7 @@ void to_utf8_test() |
| 171 | 170 | { |
| 172 | 171 | print_utf8(0x80000000UL); |
| 173 | 172 | } |
| 174 | - catch (QEXC::General& e) | |
| 173 | + catch (std::runtime_error& e) | |
| 175 | 174 | { |
| 176 | 175 | std::cout << "0x80000000: " << e.what() << std::endl; |
| 177 | 176 | } | ... | ... |
libtests/rc4.cc
qpdf/qpdf.cc
| 1 | - | |
| 2 | 1 | #include <iostream> |
| 3 | 2 | #include <string.h> |
| 4 | 3 | #include <stdlib.h> |
| ... | ... | @@ -943,7 +942,7 @@ int main(int argc, char* argv[]) |
| 943 | 942 | } |
| 944 | 943 | else |
| 945 | 944 | { |
| 946 | - throw QEXC::Internal("bad encryption keylen"); | |
| 945 | + throw std::logic_error("bad encryption keylen"); | |
| 947 | 946 | } |
| 948 | 947 | } |
| 949 | 948 | if (linearize) | ... | ... |
qpdf/test_driver.cc
| ... | ... | @@ -284,8 +284,8 @@ void runtest(int n, char const* filename) |
| 284 | 284 | } |
| 285 | 285 | else |
| 286 | 286 | { |
| 287 | - throw QEXC::General(std::string("invalid test ") + | |
| 288 | - QUtil::int_to_string(n)); | |
| 287 | + throw std::runtime_error(std::string("invalid test ") + | |
| 288 | + QUtil::int_to_string(n)); | |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | std::cout << "test " << n << " done" << std::endl; | ... | ... |