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
| 1 | +2009-09-26 Jay Berkenbilt <ejb@ql.org> | ||
| 2 | + | ||
| 3 | + * Removed all references to QEXC; now using std::runtime_error and | ||
| 4 | + std::logic_error and their subclasses for all exceptions. | ||
| 5 | + | ||
| 1 | 2009-05-03 Jay Berkenbilt <ejb@ql.org> | 6 | 2009-05-03 Jay Berkenbilt <ejb@ql.org> |
| 2 | 7 | ||
| 3 | * 2.0.6. release | 8 | * 2.0.6. release |
TODO
| 1 | 2.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 | * Add ability to create new streams or replace stream data. Consider | 9 | * Add ability to create new streams or replace stream data. Consider |
| 5 | stream data sources to include a file and offset, a buffer, or a | 10 | stream data sources to include a file and offset, a buffer, or a |
| 6 | some kind of callback mechanism. Find messages exchanged with | 11 | some kind of callback mechanism. Find messages exchanged with |
include/qpdf/Pipeline.hh
| @@ -31,27 +31,11 @@ | @@ -31,27 +31,11 @@ | ||
| 31 | #define __PIPELINE_HH__ | 31 | #define __PIPELINE_HH__ |
| 32 | 32 | ||
| 33 | #include <qpdf/DLL.hh> | 33 | #include <qpdf/DLL.hh> |
| 34 | - | ||
| 35 | -#include <qpdf/QEXC.hh> | 34 | +#include <string> |
| 36 | 35 | ||
| 37 | class Pipeline | 36 | class Pipeline |
| 38 | { | 37 | { |
| 39 | public: | 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 | DLL_EXPORT | 39 | DLL_EXPORT |
| 56 | Pipeline(char const* identifier, Pipeline* next); | 40 | Pipeline(char const* identifier, Pipeline* next); |
| 57 | 41 |
include/qpdf/Pl_Flate.hh
| @@ -15,21 +15,6 @@ | @@ -15,21 +15,6 @@ | ||
| 15 | class Pl_Flate: public Pipeline | 15 | class Pl_Flate: public Pipeline |
| 16 | { | 16 | { |
| 17 | public: | 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 | static int const def_bufsize = 65536; | 18 | static int const def_bufsize = 65536; |
| 34 | 19 | ||
| 35 | enum action_e { a_inflate, a_deflate }; | 20 | enum action_e { a_inflate, a_deflate }; |
include/qpdf/Pl_StdioFile.hh
| @@ -21,21 +21,6 @@ | @@ -21,21 +21,6 @@ | ||
| 21 | class Pl_StdioFile: public Pipeline | 21 | class Pl_StdioFile: public Pipeline |
| 22 | { | 22 | { |
| 23 | public: | 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 | // f is externally maintained; this class just writes to and | 24 | // f is externally maintained; this class just writes to and |
| 40 | // flushes it. It does not close it. | 25 | // flushes it. It does not close it. |
| 41 | DLL_EXPORT | 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,9 +8,10 @@ | ||
| 8 | #ifndef __QPDFEXC_HH__ | 8 | #ifndef __QPDFEXC_HH__ |
| 9 | #define __QPDFEXC_HH__ | 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 | public: | 16 | public: |
| 16 | DLL_EXPORT | 17 | DLL_EXPORT |
include/qpdf/QUtil.hh
| @@ -8,13 +8,13 @@ | @@ -8,13 +8,13 @@ | ||
| 8 | #ifndef __QUTIL_HH__ | 8 | #ifndef __QUTIL_HH__ |
| 9 | #define __QUTIL_HH__ | 9 | #define __QUTIL_HH__ |
| 10 | 10 | ||
| 11 | +#include <qpdf/DLL.hh> | ||
| 11 | #include <string> | 12 | #include <string> |
| 12 | #include <list> | 13 | #include <list> |
| 14 | +#include <stdexcept> | ||
| 13 | #include <stdio.h> | 15 | #include <stdio.h> |
| 14 | #include <sys/stat.h> | 16 | #include <sys/stat.h> |
| 15 | 17 | ||
| 16 | -#include <qpdf/QEXC.hh> | ||
| 17 | - | ||
| 18 | namespace QUtil | 18 | namespace QUtil |
| 19 | { | 19 | { |
| 20 | // This is a collection of useful utility functions that don't | 20 | // This is a collection of useful utility functions that don't |
| @@ -24,15 +24,25 @@ namespace QUtil | @@ -24,15 +24,25 @@ namespace QUtil | ||
| 24 | DLL_EXPORT | 24 | DLL_EXPORT |
| 25 | std::string double_to_string(double, int decimal_places = 0); | 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 | DLL_EXPORT | 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 | DLL_EXPORT | 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 | DLL_EXPORT | 47 | DLL_EXPORT |
| 38 | char* copy_string(std::string const&); | 48 | char* copy_string(std::string const&); |
libqpdf/BitStream.cc
| @@ -38,7 +38,8 @@ BitStream::skipToNextByte() | @@ -38,7 +38,8 @@ BitStream::skipToNextByte() | ||
| 38 | unsigned int bits_to_skip = bit_offset + 1; | 38 | unsigned int bits_to_skip = bit_offset + 1; |
| 39 | if (bits_available < bits_to_skip) | 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 | bit_offset = 7; | 44 | bit_offset = 7; |
| 44 | ++p; | 45 | ++p; |
libqpdf/BitWriter.cc
libqpdf/Buffer.cc
libqpdf/MD5.cc
| @@ -28,6 +28,7 @@ | @@ -28,6 +28,7 @@ | ||
| 28 | ///////////////////////////////////////////////////////////////////////// | 28 | ///////////////////////////////////////////////////////////////////////// |
| 29 | 29 | ||
| 30 | #include <qpdf/MD5.hh> | 30 | #include <qpdf/MD5.hh> |
| 31 | +#include <qpdf/QUtil.hh> | ||
| 31 | 32 | ||
| 32 | #include <stdio.h> | 33 | #include <stdio.h> |
| 33 | #include <memory.h> | 34 | #include <memory.h> |
| @@ -330,15 +331,12 @@ void MD5::encodeDataIncrementally(char const* data, int len) | @@ -330,15 +331,12 @@ void MD5::encodeDataIncrementally(char const* data, int len) | ||
| 330 | 331 | ||
| 331 | DLL_EXPORT | 332 | DLL_EXPORT |
| 332 | void MD5::encodeFile(char const *filename, int up_to_size) | 333 | void MD5::encodeFile(char const *filename, int up_to_size) |
| 333 | - throw (QEXC::System) | ||
| 334 | { | 334 | { |
| 335 | - FILE *file; | ||
| 336 | unsigned char buffer[1024]; | 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 | int len; | 341 | int len; |
| 344 | int so_far = 0; | 342 | int so_far = 0; |
| @@ -365,7 +363,8 @@ void MD5::encodeFile(char const *filename, int up_to_size) | @@ -365,7 +363,8 @@ void MD5::encodeFile(char const *filename, int up_to_size) | ||
| 365 | // Assume, perhaps incorrectly, that errno was set by the | 363 | // Assume, perhaps incorrectly, that errno was set by the |
| 366 | // underlying call to read.... | 364 | // underlying call to read.... |
| 367 | (void) fclose(file); | 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 | (void) fclose(file); | 369 | (void) fclose(file); |
| 371 | 370 | ||
| @@ -446,7 +445,7 @@ MD5::checkFileChecksum(char const* const checksum, | @@ -446,7 +445,7 @@ MD5::checkFileChecksum(char const* const checksum, | ||
| 446 | std::string actual_checksum = getFileChecksum(filename, up_to_size); | 445 | std::string actual_checksum = getFileChecksum(filename, up_to_size); |
| 447 | result = (checksum == actual_checksum); | 446 | result = (checksum == actual_checksum); |
| 448 | } | 447 | } |
| 449 | - catch (QEXC::System) | 448 | + catch (std::runtime_error) |
| 450 | { | 449 | { |
| 451 | // Ignore -- return false | 450 | // Ignore -- return false |
| 452 | } | 451 | } |
libqpdf/PCRE.cc
| 1 | - | ||
| 2 | #include <qpdf/PCRE.hh> | 1 | #include <qpdf/PCRE.hh> |
| 3 | #include <qpdf/QUtil.hh> | 2 | #include <qpdf/QUtil.hh> |
| 4 | 3 | ||
| 4 | +#include <stdexcept> | ||
| 5 | #include <iostream> | 5 | #include <iostream> |
| 6 | #include <string.h> | 6 | #include <string.h> |
| 7 | 7 | ||
| 8 | DLL_EXPORT | 8 | DLL_EXPORT |
| 9 | -PCRE::Exception::Exception(std::string const& message) | ||
| 10 | -{ | ||
| 11 | - this->setMessage("PCRE error: " + message); | ||
| 12 | -} | ||
| 13 | - | ||
| 14 | -DLL_EXPORT | ||
| 15 | PCRE::NoBackref::NoBackref() : | 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,7 +81,6 @@ PCRE::Match::operator bool() | ||
| 87 | DLL_EXPORT | 81 | DLL_EXPORT |
| 88 | std::string | 82 | std::string |
| 89 | PCRE::Match::getMatch(int n, int flags) | 83 | PCRE::Match::getMatch(int n, int flags) |
| 90 | - throw(QEXC::General, Exception) | ||
| 91 | { | 84 | { |
| 92 | // This method used to be implemented in terms of | 85 | // This method used to be implemented in terms of |
| 93 | // pcre_get_substring, but that function gives you an empty string | 86 | // pcre_get_substring, but that function gives you an empty string |
| @@ -116,7 +109,7 @@ PCRE::Match::getMatch(int n, int flags) | @@ -116,7 +109,7 @@ PCRE::Match::getMatch(int n, int flags) | ||
| 116 | 109 | ||
| 117 | DLL_EXPORT | 110 | DLL_EXPORT |
| 118 | void | 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 | if ((this->nmatches < 0) || | 114 | if ((this->nmatches < 0) || |
| 122 | (n > this->nmatches - 1) || | 115 | (n > this->nmatches - 1) || |
| @@ -130,7 +123,7 @@ PCRE::Match::getOffsetLength(int n, int& offset, int& length) throw(Exception) | @@ -130,7 +123,7 @@ PCRE::Match::getOffsetLength(int n, int& offset, int& length) throw(Exception) | ||
| 130 | 123 | ||
| 131 | DLL_EXPORT | 124 | DLL_EXPORT |
| 132 | int | 125 | int |
| 133 | -PCRE::Match::getOffset(int n) throw(Exception) | 126 | +PCRE::Match::getOffset(int n) |
| 134 | { | 127 | { |
| 135 | int offset; | 128 | int offset; |
| 136 | int length; | 129 | int length; |
| @@ -140,7 +133,7 @@ PCRE::Match::getOffset(int n) throw(Exception) | @@ -140,7 +133,7 @@ PCRE::Match::getOffset(int n) throw(Exception) | ||
| 140 | 133 | ||
| 141 | DLL_EXPORT | 134 | DLL_EXPORT |
| 142 | int | 135 | int |
| 143 | -PCRE::Match::getLength(int n) throw(Exception) | 136 | +PCRE::Match::getLength(int n) |
| 144 | { | 137 | { |
| 145 | int offset; | 138 | int offset; |
| 146 | int length; | 139 | int length; |
| @@ -156,7 +149,7 @@ PCRE::Match::nMatches() const | @@ -156,7 +149,7 @@ PCRE::Match::nMatches() const | ||
| 156 | } | 149 | } |
| 157 | 150 | ||
| 158 | DLL_EXPORT | 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 | char const *errptr; | 154 | char const *errptr; |
| 162 | int erroffset; | 155 | int erroffset; |
| @@ -171,7 +164,7 @@ PCRE::PCRE(char const* pattern, int options) throw (PCRE::Exception) | @@ -171,7 +164,7 @@ PCRE::PCRE(char const* pattern, int options) throw (PCRE::Exception) | ||
| 171 | " failed at offset " + | 164 | " failed at offset " + |
| 172 | QUtil::int_to_string(erroffset) + ": " + | 165 | QUtil::int_to_string(erroffset) + ": " + |
| 173 | errptr); | 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,7 +177,6 @@ PCRE::~PCRE() | ||
| 184 | DLL_EXPORT | 177 | DLL_EXPORT |
| 185 | PCRE::Match | 178 | PCRE::Match |
| 186 | PCRE::match(char const* subject, int options, int startoffset, int size) | 179 | PCRE::match(char const* subject, int options, int startoffset, int size) |
| 187 | - throw (QEXC::General, Exception) | ||
| 188 | { | 180 | { |
| 189 | if (size == -1) | 181 | if (size == -1) |
| 190 | { | 182 | { |
| @@ -210,12 +202,12 @@ PCRE::match(char const* subject, int options, int startoffset, int size) | @@ -210,12 +202,12 @@ PCRE::match(char const* subject, int options, int startoffset, int size) | ||
| 210 | 202 | ||
| 211 | case PCRE_ERROR_BADOPTION: | 203 | case PCRE_ERROR_BADOPTION: |
| 212 | message = "bad option passed to PCRE::match()"; | 204 | message = "bad option passed to PCRE::match()"; |
| 213 | - throw Exception(message); | 205 | + throw std::logic_error(message); |
| 214 | break; | 206 | break; |
| 215 | 207 | ||
| 216 | case PCRE_ERROR_NOMEMORY: | 208 | case PCRE_ERROR_NOMEMORY: |
| 217 | message = "insufficient memory"; | 209 | message = "insufficient memory"; |
| 218 | - throw Exception(message); | 210 | + throw std::runtime_error(message); |
| 219 | break; | 211 | break; |
| 220 | 212 | ||
| 221 | case PCRE_ERROR_NULL: | 213 | case PCRE_ERROR_NULL: |
| @@ -223,7 +215,7 @@ PCRE::match(char const* subject, int options, int startoffset, int size) | @@ -223,7 +215,7 @@ PCRE::match(char const* subject, int options, int startoffset, int size) | ||
| 223 | case PCRE_ERROR_UNKNOWN_NODE: | 215 | case PCRE_ERROR_UNKNOWN_NODE: |
| 224 | default: | 216 | default: |
| 225 | message = "pcre_exec returned " + QUtil::int_to_string(status); | 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,9 +250,9 @@ PCRE::test(int n) | ||
| 258 | { | 250 | { |
| 259 | PCRE pcre1("a**"); | 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 | PCRE pcre2("^([^\\s:]*)\\s*:\\s*(.*?)\\s*$"); | 258 | PCRE pcre2("^([^\\s:]*)\\s*:\\s*(.*?)\\s*$"); |
| @@ -281,17 +273,17 @@ PCRE::test(int n) | @@ -281,17 +273,17 @@ PCRE::test(int n) | ||
| 281 | { | 273 | { |
| 282 | std::cout << m2.getMatch(3) << std::endl; | 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 | try | 280 | try |
| 289 | { | 281 | { |
| 290 | std::cout << m2.getOffset(3) << std::endl; | 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 | PCRE pcre3("^(a+)(b+)?$"); | 289 | PCRE pcre3("^(a+)(b+)?$"); |
| @@ -312,9 +304,9 @@ PCRE::test(int n) | @@ -312,9 +304,9 @@ PCRE::test(int n) | ||
| 312 | std::cout << "can't see this" << std::endl; | 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 | // backref: 1 2 3 4 5 | 312 | // backref: 1 2 3 4 5 |
| @@ -370,8 +362,8 @@ PCRE::test(int n) | @@ -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 | #include <qpdf/Pipeline.hh> | 1 | #include <qpdf/Pipeline.hh> |
| 2 | +#include <stdexcept> | ||
| 4 | 3 | ||
| 5 | DLL_EXPORT | 4 | DLL_EXPORT |
| 6 | Pipeline::Pipeline(char const* identifier, Pipeline* next) : | 5 | Pipeline::Pipeline(char const* identifier, Pipeline* next) : |
| @@ -19,7 +18,7 @@ Pipeline::getNext(bool allow_null) | @@ -19,7 +18,7 @@ Pipeline::getNext(bool allow_null) | ||
| 19 | { | 18 | { |
| 20 | if ((next == 0) && (! allow_null)) | 19 | if ((next == 0) && (! allow_null)) |
| 21 | { | 20 | { |
| 22 | - throw Exception( | 21 | + throw std::logic_error( |
| 23 | this->identifier + | 22 | this->identifier + |
| 24 | ": Pipeline::getNext() called on pipeline with no next"); | 23 | ": Pipeline::getNext() called on pipeline with no next"); |
| 25 | } | 24 | } |
libqpdf/Pl_ASCII85Decoder.cc
| 1 | #include <qpdf/Pl_ASCII85Decoder.hh> | 1 | #include <qpdf/Pl_ASCII85Decoder.hh> |
| 2 | -#include <qpdf/QEXC.hh> | ||
| 3 | #include <qpdf/QTC.hh> | 2 | #include <qpdf/QTC.hh> |
| 3 | +#include <stdexcept> | ||
| 4 | #include <string.h> | 4 | #include <string.h> |
| 5 | 5 | ||
| 6 | DLL_EXPORT | 6 | DLL_EXPORT |
| @@ -40,7 +40,7 @@ Pl_ASCII85Decoder::write(unsigned char* buf, int len) | @@ -40,7 +40,7 @@ Pl_ASCII85Decoder::write(unsigned char* buf, int len) | ||
| 40 | } | 40 | } |
| 41 | else | 41 | else |
| 42 | { | 42 | { |
| 43 | - throw QEXC::General( | 43 | + throw std::runtime_error( |
| 44 | "broken end-of-data sequence in base 85 data"); | 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,7 +65,7 @@ Pl_ASCII85Decoder::write(unsigned char* buf, int len) | ||
| 65 | case 'z': | 65 | case 'z': |
| 66 | if (pos != 0) | 66 | if (pos != 0) |
| 67 | { | 67 | { |
| 68 | - throw QEXC::General( | 68 | + throw std::runtime_error( |
| 69 | "unexpected z during base 85 decode"); | 69 | "unexpected z during base 85 decode"); |
| 70 | } | 70 | } |
| 71 | else | 71 | else |
| @@ -78,8 +78,8 @@ Pl_ASCII85Decoder::write(unsigned char* buf, int len) | @@ -78,8 +78,8 @@ Pl_ASCII85Decoder::write(unsigned char* buf, int len) | ||
| 78 | default: | 78 | default: |
| 79 | if ((buf[i] < 33) || (buf[i] > 117)) | 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 | else | 84 | else |
| 85 | { | 85 | { |
libqpdf/Pl_ASCIIHexDecoder.cc
| 1 | #include <qpdf/Pl_ASCIIHexDecoder.hh> | 1 | #include <qpdf/Pl_ASCIIHexDecoder.hh> |
| 2 | -#include <qpdf/QEXC.hh> | ||
| 3 | #include <qpdf/QTC.hh> | 2 | #include <qpdf/QTC.hh> |
| 3 | +#include <stdexcept> | ||
| 4 | #include <string.h> | 4 | #include <string.h> |
| 5 | #include <ctype.h> | 5 | #include <ctype.h> |
| 6 | 6 | ||
| @@ -61,8 +61,9 @@ Pl_ASCIIHexDecoder::write(unsigned char* buf, int len) | @@ -61,8 +61,9 @@ Pl_ASCIIHexDecoder::write(unsigned char* buf, int len) | ||
| 61 | char t[2]; | 61 | char t[2]; |
| 62 | t[0] = ch; | 62 | t[0] = ch; |
| 63 | t[1] = 0; | 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 | break; | 68 | break; |
| 68 | } | 69 | } |
libqpdf/Pl_Buffer.cc
| 1 | - | ||
| 2 | #include <qpdf/Pl_Buffer.hh> | 1 | #include <qpdf/Pl_Buffer.hh> |
| 3 | -#include <qpdf/QEXC.hh> | 2 | +#include <stdexcept> |
| 4 | #include <assert.h> | 3 | #include <assert.h> |
| 5 | #include <string.h> | 4 | #include <string.h> |
| 6 | 5 | ||
| @@ -50,7 +49,7 @@ Pl_Buffer::getBuffer() | @@ -50,7 +49,7 @@ Pl_Buffer::getBuffer() | ||
| 50 | { | 49 | { |
| 51 | if (! this->ready) | 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 | Buffer* b = new Buffer(this->total_size); | 55 | Buffer* b = new Buffer(this->total_size); |
libqpdf/Pl_Count.cc
libqpdf/Pl_Discard.cc
libqpdf/Pl_Flate.cc
| 1 | - | ||
| 2 | #include <qpdf/Pl_Flate.hh> | 1 | #include <qpdf/Pl_Flate.hh> |
| 3 | 2 | ||
| 4 | #include <qpdf/QUtil.hh> | 3 | #include <qpdf/QUtil.hh> |
| @@ -38,7 +37,7 @@ Pl_Flate::write(unsigned char* data, int len) | @@ -38,7 +37,7 @@ Pl_Flate::write(unsigned char* data, int len) | ||
| 38 | { | 37 | { |
| 39 | if (this->outbuf == 0) | 38 | if (this->outbuf == 0) |
| 40 | { | 39 | { |
| 41 | - throw Exception( | 40 | + throw std::logic_error( |
| 42 | this->identifier + | 41 | this->identifier + |
| 43 | ": Pl_Flate: write() called after finish() called"); | 42 | ": Pl_Flate: write() called after finish() called"); |
| 44 | } | 43 | } |
| @@ -197,6 +196,6 @@ Pl_Flate::checkError(char const* prefix, int error_code) | @@ -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 | #include <qpdf/Pl_LZWDecoder.hh> | 1 | #include <qpdf/Pl_LZWDecoder.hh> |
| 2 | 2 | ||
| 3 | -#include <qpdf/QEXC.hh> | ||
| 4 | #include <qpdf/QTC.hh> | 3 | #include <qpdf/QTC.hh> |
| 4 | +#include <stdexcept> | ||
| 5 | #include <string.h> | 5 | #include <string.h> |
| 6 | #include <assert.h> | 6 | #include <assert.h> |
| 7 | 7 | ||
| @@ -185,7 +185,7 @@ Pl_LZWDecoder::handleCode(int code) | @@ -185,7 +185,7 @@ Pl_LZWDecoder::handleCode(int code) | ||
| 185 | unsigned int idx = code - 258; | 185 | unsigned int idx = code - 258; |
| 186 | if (idx > table_size) | 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 | else if (idx == table_size) | 190 | else if (idx == table_size) |
| 191 | { | 191 | { |
| @@ -204,7 +204,7 @@ Pl_LZWDecoder::handleCode(int code) | @@ -204,7 +204,7 @@ Pl_LZWDecoder::handleCode(int code) | ||
| 204 | unsigned int new_idx = 258 + table_size; | 204 | unsigned int new_idx = 258 + table_size; |
| 205 | if (new_idx == 4096) | 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 | addToTable(next); | 209 | addToTable(next); |
| 210 | unsigned int change_idx = new_idx + code_change_delta; | 210 | unsigned int change_idx = new_idx + code_change_delta; |
libqpdf/Pl_MD5.cc
| 1 | - | ||
| 2 | #include <qpdf/Pl_MD5.hh> | 1 | #include <qpdf/Pl_MD5.hh> |
| 3 | - | ||
| 4 | -#include <qpdf/QEXC.hh> | 2 | +#include <stdexcept> |
| 5 | 3 | ||
| 6 | DLL_EXPORT | 4 | DLL_EXPORT |
| 7 | Pl_MD5::Pl_MD5(char const* identifier, Pipeline* next) : | 5 | Pl_MD5::Pl_MD5(char const* identifier, Pipeline* next) : |
| @@ -42,7 +40,8 @@ Pl_MD5::getHexDigest() | @@ -42,7 +40,8 @@ Pl_MD5::getHexDigest() | ||
| 42 | { | 40 | { |
| 43 | if (this->in_progress) | 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 | return this->md5.unparse(); | 46 | return this->md5.unparse(); |
| 48 | } | 47 | } |
libqpdf/Pl_PNGFilter.cc
| 1 | - | ||
| 2 | #include <qpdf/Pl_PNGFilter.hh> | 1 | #include <qpdf/Pl_PNGFilter.hh> |
| 2 | +#include <stdexcept> | ||
| 3 | #include <string.h> | 3 | #include <string.h> |
| 4 | 4 | ||
| 5 | DLL_EXPORT | 5 | DLL_EXPORT |
| @@ -85,7 +85,7 @@ Pl_PNGFilter::decodeRow() | @@ -85,7 +85,7 @@ Pl_PNGFilter::decodeRow() | ||
| 85 | break; | 85 | break; |
| 86 | 86 | ||
| 87 | case 1: // sub | 87 | case 1: // sub |
| 88 | - throw Exception("sub filter not implemented"); | 88 | + throw std::logic_error("sub filter not implemented"); |
| 89 | break; | 89 | break; |
| 90 | 90 | ||
| 91 | case 2: // up | 91 | case 2: // up |
| @@ -96,11 +96,11 @@ Pl_PNGFilter::decodeRow() | @@ -96,11 +96,11 @@ Pl_PNGFilter::decodeRow() | ||
| 96 | break; | 96 | break; |
| 97 | 97 | ||
| 98 | case 3: // average | 98 | case 3: // average |
| 99 | - throw Exception("average filter not implemented"); | 99 | + throw std::logic_error("average filter not implemented"); |
| 100 | break; | 100 | break; |
| 101 | 101 | ||
| 102 | case 4: // Paeth | 102 | case 4: // Paeth |
| 103 | - throw Exception("Paeth filter not implemented"); | 103 | + throw std::logic_error("Paeth filter not implemented"); |
| 104 | break; | 104 | break; |
| 105 | 105 | ||
| 106 | default: | 106 | default: |
libqpdf/Pl_QPDFTokenizer.cc
| 1 | - | ||
| 2 | #include <qpdf/Pl_QPDFTokenizer.hh> | 1 | #include <qpdf/Pl_QPDFTokenizer.hh> |
| 3 | #include <qpdf/QPDF_String.hh> | 2 | #include <qpdf/QPDF_String.hh> |
| 4 | #include <qpdf/QPDF_Name.hh> | 3 | #include <qpdf/QPDF_Name.hh> |
| 4 | +#include <stdexcept> | ||
| 5 | #include <string.h> | 5 | #include <string.h> |
| 6 | 6 | ||
| 7 | Pl_QPDFTokenizer::Pl_QPDFTokenizer(char const* identifier, Pipeline* next) : | 7 | Pl_QPDFTokenizer::Pl_QPDFTokenizer(char const* identifier, Pipeline* next) : |
| @@ -134,8 +134,9 @@ Pl_QPDFTokenizer::checkUnread() | @@ -134,8 +134,9 @@ Pl_QPDFTokenizer::checkUnread() | ||
| 134 | processChar(this->char_to_unread); | 134 | processChar(this->char_to_unread); |
| 135 | if (this->unread_char) | 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 | #include <qpdf/Pl_RC4.hh> | 1 | #include <qpdf/Pl_RC4.hh> |
| 3 | - | ||
| 4 | #include <qpdf/QUtil.hh> | 2 | #include <qpdf/QUtil.hh> |
| 5 | 3 | ||
| 6 | DLL_EXPORT | 4 | DLL_EXPORT |
| @@ -30,7 +28,7 @@ Pl_RC4::write(unsigned char* data, int len) | @@ -30,7 +28,7 @@ Pl_RC4::write(unsigned char* data, int len) | ||
| 30 | { | 28 | { |
| 31 | if (this->outbuf == 0) | 29 | if (this->outbuf == 0) |
| 32 | { | 30 | { |
| 33 | - throw Exception( | 31 | + throw std::logic_error( |
| 34 | this->identifier + | 32 | this->identifier + |
| 35 | ": Pl_RC4: write() called after finish() called"); | 33 | ": Pl_RC4: write() called after finish() called"); |
| 36 | } | 34 | } |
libqpdf/Pl_StdioFile.cc
| 1 | - | ||
| 2 | #include <qpdf/Pl_StdioFile.hh> | 1 | #include <qpdf/Pl_StdioFile.hh> |
| 3 | - | 2 | +#include <qpdf/QUtil.hh> |
| 3 | +#include <stdexcept> | ||
| 4 | #include <errno.h> | 4 | #include <errno.h> |
| 5 | 5 | ||
| 6 | DLL_EXPORT | 6 | DLL_EXPORT |
| @@ -25,8 +25,8 @@ Pl_StdioFile::write(unsigned char* buf, int len) | @@ -25,8 +25,8 @@ Pl_StdioFile::write(unsigned char* buf, int len) | ||
| 25 | so_far = fwrite(buf, 1, len, this->file); | 25 | so_far = fwrite(buf, 1, len, this->file); |
| 26 | if (so_far == 0) | 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 | else | 31 | else |
| 32 | { | 32 | { |
| @@ -46,7 +46,8 @@ Pl_StdioFile::finish() | @@ -46,7 +46,8 @@ Pl_StdioFile::finish() | ||
| 46 | } | 46 | } |
| 47 | else | 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 | #include <qpdf/QPDF.hh> | 1 | #include <qpdf/QPDF.hh> |
| 3 | 2 | ||
| 4 | #include <vector> | 3 | #include <vector> |
| @@ -197,7 +196,8 @@ QPDF::BufferInputSource::seek(off_t offset, int whence) | @@ -197,7 +196,8 @@ QPDF::BufferInputSource::seek(off_t offset, int whence) | ||
| 197 | break; | 196 | break; |
| 198 | 197 | ||
| 199 | default: | 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 | break; | 201 | break; |
| 202 | } | 202 | } |
| 203 | } | 203 | } |
| @@ -392,7 +392,7 @@ QPDF::parse() | @@ -392,7 +392,7 @@ QPDF::parse() | ||
| 392 | void | 392 | void |
| 393 | QPDF::warn(QPDFExc const& e) | 393 | QPDF::warn(QPDFExc const& e) |
| 394 | { | 394 | { |
| 395 | - this->warnings.push_back(e.unparse()); | 395 | + this->warnings.push_back(e.what()); |
| 396 | if (! this->suppress_warnings) | 396 | if (! this->suppress_warnings) |
| 397 | { | 397 | { |
| 398 | std::cerr << "WARNING: " << this->warnings.back() << std::endl; | 398 | std::cerr << "WARNING: " << this->warnings.back() << std::endl; |
| @@ -956,8 +956,8 @@ QPDF::showXRefTable() | @@ -956,8 +956,8 @@ QPDF::showXRefTable() | ||
| 956 | break; | 956 | break; |
| 957 | 957 | ||
| 958 | default: | 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 | break; | 961 | break; |
| 962 | } | 962 | } |
| 963 | std::cout << std::endl; | 963 | std::cout << std::endl; |
| @@ -988,7 +988,8 @@ QPDF::readObjectInternal(InputSource* input, | @@ -988,7 +988,8 @@ QPDF::readObjectInternal(InputSource* input, | ||
| 988 | // Although dictionaries and arrays arbitrarily nest, these | 988 | // Although dictionaries and arrays arbitrarily nest, these |
| 989 | // variables indicate what is at the top of the stack right | 989 | // variables indicate what is at the top of the stack right |
| 990 | // now, so they can, by definition, never both be true. | 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 | QPDFObjectHandle object; | 995 | QPDFObjectHandle object; |
| @@ -1121,9 +1122,10 @@ QPDF::readObjectInternal(InputSource* input, | @@ -1121,9 +1122,10 @@ QPDF::readObjectInternal(InputSource* input, | ||
| 1121 | } | 1122 | } |
| 1122 | else if (! object.isInitialized()) | 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 | else | 1130 | else |
| 1129 | { | 1131 | { |
| @@ -1846,13 +1848,13 @@ QPDF::pipeStreamData(int objid, int generation, | @@ -1846,13 +1848,13 @@ QPDF::pipeStreamData(int objid, int generation, | ||
| 1846 | pipeline->write((unsigned char*)buf, len); | 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 | QTC::TC("qpdf", "QPDF decoding error warning"); | 1853 | QTC::TC("qpdf", "QPDF decoding error warning"); |
| 1852 | warn(QPDFExc(this->file.getName(), this->file.getLastOffset(), | 1854 | warn(QPDFExc(this->file.getName(), this->file.getLastOffset(), |
| 1853 | "error decoding stream data for object " + | 1855 | "error decoding stream data for object " + |
| 1854 | QUtil::int_to_string(objid) + " " + | 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 | pipeline->finish(); | 1859 | pipeline->finish(); |
| 1858 | } | 1860 | } |
libqpdf/QPDFExc.cc
| 1 | - | ||
| 2 | #include <qpdf/QPDFExc.hh> | 1 | #include <qpdf/QPDFExc.hh> |
| 3 | - | ||
| 4 | #include <qpdf/QUtil.hh> | 2 | #include <qpdf/QUtil.hh> |
| 5 | 3 | ||
| 6 | DLL_EXPORT | 4 | DLL_EXPORT |
| 7 | QPDFExc::QPDFExc(std::string const& message) : | 5 | QPDFExc::QPDFExc(std::string const& message) : |
| 8 | - QEXC::General(message) | 6 | + std::runtime_error(message) |
| 9 | { | 7 | { |
| 10 | } | 8 | } |
| 11 | 9 | ||
| 12 | DLL_EXPORT | 10 | DLL_EXPORT |
| 13 | QPDFExc::QPDFExc(std::string const& filename, int offset, | 11 | QPDFExc::QPDFExc(std::string const& filename, int offset, |
| 14 | std::string const& message) : | 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 | #include <qpdf/QPDFObjectHandle.hh> | 1 | #include <qpdf/QPDFObjectHandle.hh> |
| 3 | 2 | ||
| 4 | #include <qpdf/QPDF.hh> | 3 | #include <qpdf/QPDF.hh> |
| @@ -13,9 +12,9 @@ | @@ -13,9 +12,9 @@ | ||
| 13 | #include <qpdf/QPDF_Stream.hh> | 12 | #include <qpdf/QPDF_Stream.hh> |
| 14 | 13 | ||
| 15 | #include <qpdf/QTC.hh> | 14 | #include <qpdf/QTC.hh> |
| 16 | -#include <qpdf/QEXC.hh> | ||
| 17 | #include <qpdf/QUtil.hh> | 15 | #include <qpdf/QUtil.hh> |
| 18 | 16 | ||
| 17 | +#include <stdexcept> | ||
| 19 | #include <stdlib.h> | 18 | #include <stdlib.h> |
| 20 | 19 | ||
| 21 | DLL_EXPORT | 20 | DLL_EXPORT |
| @@ -114,7 +113,7 @@ QPDFObjectHandle::getNumericValue() | @@ -114,7 +113,7 @@ QPDFObjectHandle::getNumericValue() | ||
| 114 | } | 113 | } |
| 115 | else | 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 | return result; | 118 | return result; |
| 120 | } | 119 | } |
| @@ -416,9 +415,10 @@ QPDFObjectHandle::getPageContents() | @@ -416,9 +415,10 @@ QPDFObjectHandle::getPageContents() | ||
| 416 | } | 415 | } |
| 417 | else | 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,8 +428,8 @@ QPDFObjectHandle::getPageContents() | ||
| 428 | } | 428 | } |
| 429 | else | 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 | return result; | 435 | return result; |
| @@ -542,7 +542,8 @@ QPDFObjectHandle::makeDirectInternal(std::set<int>& visited) | @@ -542,7 +542,8 @@ QPDFObjectHandle::makeDirectInternal(std::set<int>& visited) | ||
| 542 | if (isStream()) | 542 | if (isStream()) |
| 543 | { | 543 | { |
| 544 | QTC::TC("qpdf", "QPDFObjectHandle ERR clone stream"); | 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 | int cur_objid = this->objid; | 549 | int cur_objid = this->objid; |
| @@ -551,8 +552,9 @@ QPDFObjectHandle::makeDirectInternal(std::set<int>& visited) | @@ -551,8 +552,9 @@ QPDFObjectHandle::makeDirectInternal(std::set<int>& visited) | ||
| 551 | if (visited.count(cur_objid)) | 552 | if (visited.count(cur_objid)) |
| 552 | { | 553 | { |
| 553 | QTC::TC("qpdf", "QPDFObjectHandle makeDirect loop"); | 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 | visited.insert(cur_objid); | 559 | visited.insert(cur_objid); |
| 558 | } | 560 | } |
| @@ -620,8 +622,8 @@ QPDFObjectHandle::makeDirectInternal(std::set<int>& visited) | @@ -620,8 +622,8 @@ QPDFObjectHandle::makeDirectInternal(std::set<int>& visited) | ||
| 620 | } | 622 | } |
| 621 | else | 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 | this->obj = new_obj; | 629 | this->obj = new_obj; |
| @@ -644,8 +646,8 @@ QPDFObjectHandle::assertInitialized() const | @@ -644,8 +646,8 @@ QPDFObjectHandle::assertInitialized() const | ||
| 644 | { | 646 | { |
| 645 | if (! this->initialized) | 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,8 +656,8 @@ QPDFObjectHandle::assertType(char const* type_name, bool istype) | ||
| 654 | { | 656 | { |
| 655 | if (! istype) | 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,7 +667,7 @@ QPDFObjectHandle::assertPageObject() | ||
| 665 | if (! (this->isDictionary() && this->hasKey("/Type") && | 667 | if (! (this->isDictionary() && this->hasKey("/Type") && |
| 666 | (this->getKey("/Type").getName() == "/Page"))) | 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 | #include <qpdf/QPDFTokenizer.hh> | 1 | #include <qpdf/QPDFTokenizer.hh> |
| 3 | 2 | ||
| 4 | // DO NOT USE ctype -- it is locale dependent for some things, and | 3 | // DO NOT USE ctype -- it is locale dependent for some things, and |
| @@ -6,9 +5,9 @@ | @@ -6,9 +5,9 @@ | ||
| 6 | // be used. | 5 | // be used. |
| 7 | 6 | ||
| 8 | #include <qpdf/PCRE.hh> | 7 | #include <qpdf/PCRE.hh> |
| 9 | -#include <qpdf/QEXC.hh> | ||
| 10 | #include <qpdf/QTC.hh> | 8 | #include <qpdf/QTC.hh> |
| 11 | 9 | ||
| 10 | +#include <stdexcept> | ||
| 12 | #include <string.h> | 11 | #include <string.h> |
| 13 | 12 | ||
| 14 | // See note above about ctype. | 13 | // See note above about ctype. |
| @@ -55,8 +54,9 @@ QPDFTokenizer::presentCharacter(char ch) | @@ -55,8 +54,9 @@ QPDFTokenizer::presentCharacter(char ch) | ||
| 55 | 54 | ||
| 56 | if (state == st_token_ready) | 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 | char orig_ch = ch; | 62 | char orig_ch = ch; |
| @@ -237,8 +237,9 @@ QPDFTokenizer::presentCharacter(char ch) | @@ -237,8 +237,9 @@ QPDFTokenizer::presentCharacter(char ch) | ||
| 237 | // last_char_was_bs is set/cleared below as appropriate | 237 | // last_char_was_bs is set/cleared below as appropriate |
| 238 | if (bs_num_count) | 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 | else if (ch == '(') | 245 | else if (ch == '(') |
| @@ -333,7 +334,8 @@ QPDFTokenizer::presentCharacter(char ch) | @@ -333,7 +334,8 @@ QPDFTokenizer::presentCharacter(char ch) | ||
| 333 | } | 334 | } |
| 334 | else | 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 | if ((state == st_token_ready) && (type == tt_word)) | 341 | if ((state == st_token_ready) && (type == tt_word)) |
libqpdf/QPDFWriter.cc
| 1 | - | ||
| 2 | #include <qpdf/QPDFWriter.hh> | 1 | #include <qpdf/QPDFWriter.hh> |
| 3 | 2 | ||
| 4 | #include <assert.h> | 3 | #include <assert.h> |
| @@ -479,8 +478,8 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | @@ -479,8 +478,8 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | ||
| 479 | } | 478 | } |
| 480 | else if (object.isScalar()) | 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 | std::string(this->filename) + " " + | 483 | std::string(this->filename) + " " + |
| 485 | QUtil::int_to_string(object.getObjectID()) + " " + | 484 | QUtil::int_to_string(object.getObjectID()) + " " + |
| 486 | QUtil::int_to_string(object.getGeneration())); | 485 | QUtil::int_to_string(object.getGeneration())); |
| @@ -559,8 +558,8 @@ QPDFWriter::unparseChild(QPDFObjectHandle child, int level, int flags) | @@ -559,8 +558,8 @@ QPDFWriter::unparseChild(QPDFObjectHandle child, int level, int flags) | ||
| 559 | { | 558 | { |
| 560 | if (child.isScalar()) | 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 | QUtil::int_to_string(child.getObjectID()) + " " + | 563 | QUtil::int_to_string(child.getObjectID()) + " " + |
| 565 | QUtil::int_to_string(child.getGeneration())); | 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,7 +1598,7 @@ QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset, | ||
| 1599 | break; | 1598 | break; |
| 1600 | 1599 | ||
| 1601 | default: | 1600 | default: |
| 1602 | - throw QEXC::Internal("invalid type writing xref stream"); | 1601 | + throw std::logic_error("invalid type writing xref stream"); |
| 1603 | break; | 1602 | break; |
| 1604 | } | 1603 | } |
| 1605 | } | 1604 | } |
libqpdf/QPDFXRefEntry.cc
libqpdf/QPDF_Array.cc
| 1 | - | ||
| 2 | #include <qpdf/QPDF_Array.hh> | 1 | #include <qpdf/QPDF_Array.hh> |
| 3 | - | ||
| 4 | -#include <qpdf/QEXC.hh> | 2 | +#include <stdexcept> |
| 5 | 3 | ||
| 6 | QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& items) : | 4 | QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& items) : |
| 7 | items(items) | 5 | items(items) |
| @@ -37,7 +35,8 @@ QPDF_Array::getItem(int n) const | @@ -37,7 +35,8 @@ QPDF_Array::getItem(int n) const | ||
| 37 | { | 35 | { |
| 38 | if ((n < 0) || (n >= (int)this->items.size())) | 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 | return this->items[n]; | 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 | #include <qpdf/QPDF_Stream.hh> | 1 | #include <qpdf/QPDF_Stream.hh> |
| 3 | 2 | ||
| 4 | -#include <qpdf/QEXC.hh> | ||
| 5 | #include <qpdf/QUtil.hh> | 3 | #include <qpdf/QUtil.hh> |
| 6 | #include <qpdf/Pipeline.hh> | 4 | #include <qpdf/Pipeline.hh> |
| 7 | #include <qpdf/Pl_Flate.hh> | 5 | #include <qpdf/Pl_Flate.hh> |
| @@ -17,6 +15,8 @@ | @@ -17,6 +15,8 @@ | ||
| 17 | #include <qpdf/QPDFExc.hh> | 15 | #include <qpdf/QPDFExc.hh> |
| 18 | #include <qpdf/Pl_QPDFTokenizer.hh> | 16 | #include <qpdf/Pl_QPDFTokenizer.hh> |
| 19 | 17 | ||
| 18 | +#include <stdexcept> | ||
| 19 | + | ||
| 20 | QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation, | 20 | QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation, |
| 21 | QPDFObjectHandle stream_dict, | 21 | QPDFObjectHandle stream_dict, |
| 22 | off_t offset, int length) : | 22 | off_t offset, int length) : |
| @@ -29,8 +29,9 @@ QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation, | @@ -29,8 +29,9 @@ QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation, | ||
| 29 | { | 29 | { |
| 30 | if (! stream_dict.isDictionary()) | 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,8 +299,9 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter, | ||
| 298 | } | 299 | } |
| 299 | else | 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,7 +386,8 @@ QPDF::getKeyForObject(int objid, int generation) | ||
| 386 | { | 386 | { |
| 387 | if (! this->encrypted) | 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 | if (! ((objid == this->cached_key_objid) && | 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,8 +1177,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1177 | { | 1177 | { |
| 1178 | // Note that we can't call optimize here because we don't know | 1178 | // Note that we can't call optimize here because we don't know |
| 1179 | // whether it should be called with or without allow changes. | 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 | // Separate objects into the categories sufficient for us to | 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,8 +1337,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1336 | break; | 1337 | break; |
| 1337 | 1338 | ||
| 1338 | case ObjUser::ou_bad: | 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 | break; | 1343 | break; |
| 1342 | } | 1344 | } |
| 1343 | } | 1345 | } |
| @@ -1444,8 +1446,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1444,8 +1446,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1444 | ObjGen first_page_og(pages[0].getObjectID(), pages[0].getGeneration()); | 1446 | ObjGen first_page_og(pages[0].getObjectID(), pages[0].getGeneration()); |
| 1445 | if (! lc_first_page_private.count(first_page_og)) | 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 | lc_first_page_private.erase(first_page_og); | 1453 | lc_first_page_private.erase(first_page_og); |
| 1451 | this->c_linp.first_page_object = pages[0].getObjectID(); | 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,7 +1495,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1492 | ObjGen page_og(pages[i].getObjectID(), pages[i].getGeneration()); | 1495 | ObjGen page_og(pages[i].getObjectID(), pages[i].getGeneration()); |
| 1493 | if (! lc_other_page_private.count(page_og)) | 1496 | if (! lc_other_page_private.count(page_og)) |
| 1494 | { | 1497 | { |
| 1495 | - throw QEXC::Internal( | 1498 | + throw std::logic_error( |
| 1499 | + "INTERNAL ERROR: " | ||
| 1496 | "QPDF::calculateLinearizationData: page object for page " + | 1500 | "QPDF::calculateLinearizationData: page object for page " + |
| 1497 | QUtil::int_to_string(i) + " not in lc_other_page_private"); | 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,8 +1526,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1522 | // That should have covered all part7 objects. | 1526 | // That should have covered all part7 objects. |
| 1523 | if (! lc_other_page_private.empty()) | 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 | "not empty after generation of part7"); | 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,7 +1606,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1601 | } | 1606 | } |
| 1602 | if (! lc_thumbnail_private.empty()) | 1607 | if (! lc_thumbnail_private.empty()) |
| 1603 | { | 1608 | { |
| 1604 | - throw QEXC::Internal( | 1609 | + throw std::logic_error( |
| 1610 | + "INTERNAL ERROR: " | ||
| 1605 | "QPDF::calculateLinearizationData: lc_thumbnail_private " | 1611 | "QPDF::calculateLinearizationData: lc_thumbnail_private " |
| 1606 | "not empty after placing thumbnails"); | 1612 | "not empty after placing thumbnails"); |
| 1607 | } | 1613 | } |
| @@ -1633,11 +1639,12 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1633,11 +1639,12 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1633 | unsigned int num_wanted = this->object_to_obj_users.size(); | 1639 | unsigned int num_wanted = this->object_to_obj_users.size(); |
| 1634 | if (num_placed != num_wanted) | 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 | // Calculate shared object hint table information including | 1650 | // Calculate shared object hint table information including |
libqpdf/QPDF_optimization.cc
| @@ -78,8 +78,9 @@ QPDF::flattenScalarReferences() | @@ -78,8 +78,9 @@ QPDF::flattenScalarReferences() | ||
| 78 | { | 78 | { |
| 79 | if (node.isScalar()) | 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 | ObjGen og(node.getObjectID(), node.getGeneration()); | 85 | ObjGen og(node.getObjectID(), node.getGeneration()); |
| 85 | if (visited.count(og) > 0) | 86 | if (visited.count(og) > 0) |
| @@ -124,7 +125,8 @@ QPDF::flattenScalarReferences() | @@ -124,7 +125,8 @@ QPDF::flattenScalarReferences() | ||
| 124 | { | 125 | { |
| 125 | // QPDF_Dictionary.getKeys() never returns null | 126 | // QPDF_Dictionary.getKeys() never returns null |
| 126 | // keys. | 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 | else if (oh.isScalar()) | 131 | else if (oh.isScalar()) |
| 130 | { | 132 | { |
libqpdf/QTC.cc
libqpdf/QUtil.cc
| 1 | - | 1 | +#include <qpdf/DLL.hh> |
| 2 | #include <qpdf/QUtil.hh> | 2 | #include <qpdf/QUtil.hh> |
| 3 | #include <stdio.h> | 3 | #include <stdio.h> |
| 4 | #include <errno.h> | 4 | #include <errno.h> |
| @@ -25,9 +25,9 @@ QUtil::int_to_string(int num, int fullpad) | @@ -25,9 +25,9 @@ QUtil::int_to_string(int num, int fullpad) | ||
| 25 | // -2 or -1 to leave space for the possible negative sign and for NUL... | 25 | // -2 or -1 to leave space for the possible negative sign and for NUL... |
| 26 | if (abs(fullpad) > (int)sizeof(t) - ((num < 0)?2:1)) | 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 | if (fullpad) | 33 | if (fullpad) |
| @@ -62,9 +62,9 @@ QUtil::double_to_string(double num, int decimal_places) | @@ -62,9 +62,9 @@ QUtil::double_to_string(double num, int decimal_places) | ||
| 62 | // always pass in those cases. | 62 | // always pass in those cases. |
| 63 | if (decimal_places + 1 + (int)lhs.length() > (int)sizeof(t) - 1) | 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 | if (decimal_places) | 70 | if (decimal_places) |
| @@ -79,23 +79,30 @@ QUtil::double_to_string(double num, int decimal_places) | @@ -79,23 +79,30 @@ QUtil::double_to_string(double num, int decimal_places) | ||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | DLL_EXPORT | 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 | int | 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 | if (status == -1) | 92 | if (status == -1) |
| 86 | { | 93 | { |
| 87 | - throw QEXC::System(description, errno); | 94 | + throw_system_error(description); |
| 88 | } | 95 | } |
| 89 | return status; | 96 | return status; |
| 90 | } | 97 | } |
| 91 | 98 | ||
| 92 | DLL_EXPORT | 99 | DLL_EXPORT |
| 93 | FILE* | 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 | if (f == 0) | 103 | if (f == 0) |
| 97 | { | 104 | { |
| 98 | - throw QEXC::System(description, errno); | 105 | + throw_system_error(description); |
| 99 | } | 106 | } |
| 100 | return f; | 107 | return f; |
| 101 | } | 108 | } |
| @@ -240,7 +247,7 @@ QUtil::toUTF8(unsigned long uval) | @@ -240,7 +247,7 @@ QUtil::toUTF8(unsigned long uval) | ||
| 240 | 247 | ||
| 241 | if (uval > 0x7fffffff) | 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 | else if (uval < 128) | 252 | else if (uval < 128) |
| 246 | { | 253 | { |
| @@ -267,7 +274,7 @@ QUtil::toUTF8(unsigned long uval) | @@ -267,7 +274,7 @@ QUtil::toUTF8(unsigned long uval) | ||
| 267 | --cur_byte; | 274 | --cur_byte; |
| 268 | if (cur_byte < bytes) | 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 | // If maxval is k bits long, the high (7 - k) bits of the | 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,8 +3,8 @@ | ||
| 3 | #define __BITS_CC__ | 3 | #define __BITS_CC__ |
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | +#include <stdexcept> | ||
| 6 | #include <qpdf/QTC.hh> | 7 | #include <qpdf/QTC.hh> |
| 7 | -#include <qpdf/QEXC.hh> | ||
| 8 | #include <qpdf/Pipeline.hh> | 8 | #include <qpdf/Pipeline.hh> |
| 9 | 9 | ||
| 10 | // These functions may be run at places where the function call | 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,11 +28,11 @@ read_bits(unsigned char const*& p, unsigned int& bit_offset, | ||
| 28 | 28 | ||
| 29 | if (bits_wanted > bits_available) | 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 | if (bits_wanted > 32) | 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 | unsigned long result = 0; | 38 | unsigned long result = 0; |
| @@ -99,7 +99,7 @@ write_bits(unsigned char& ch, unsigned int& bit_offset, | @@ -99,7 +99,7 @@ write_bits(unsigned char& ch, unsigned int& bit_offset, | ||
| 99 | { | 99 | { |
| 100 | if (bits > 32) | 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 | // bit_offset + 1 is the number of bits left in ch | 105 | // bit_offset + 1 is the number of bits left in ch |
libqpdf/build.mk
| @@ -22,7 +22,6 @@ SRCS_libqpdf = \ | @@ -22,7 +22,6 @@ SRCS_libqpdf = \ | ||
| 22 | libqpdf/Pl_QPDFTokenizer.cc \ | 22 | libqpdf/Pl_QPDFTokenizer.cc \ |
| 23 | libqpdf/Pl_RC4.cc \ | 23 | libqpdf/Pl_RC4.cc \ |
| 24 | libqpdf/Pl_StdioFile.cc \ | 24 | libqpdf/Pl_StdioFile.cc \ |
| 25 | - libqpdf/QEXC.cc \ | ||
| 26 | libqpdf/QPDF.cc \ | 25 | libqpdf/QPDF.cc \ |
| 27 | libqpdf/QPDFExc.cc \ | 26 | libqpdf/QPDFExc.cc \ |
| 28 | libqpdf/QPDFObject.cc \ | 27 | libqpdf/QPDFObject.cc \ |
| @@ -69,5 +68,5 @@ $(OBJS_libqpdf): libqpdf/$(OUTPUT_DIR)/%.lo: libqpdf/%.cc | @@ -69,5 +68,5 @@ $(OBJS_libqpdf): libqpdf/$(OUTPUT_DIR)/%.lo: libqpdf/%.cc | ||
| 69 | # * Otherwise, increment REVISION | 68 | # * Otherwise, increment REVISION |
| 70 | 69 | ||
| 71 | libqpdf/$(OUTPUT_DIR)/libqpdf.la: $(OBJS_libqpdf) | 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 | #ifndef __MD5_HH__ | 1 | #ifndef __MD5_HH__ |
| 3 | #define __MD5_HH__ | 2 | #define __MD5_HH__ |
| 4 | 3 | ||
| 5 | #include <string> | 4 | #include <string> |
| 6 | #include <qpdf/DLL.hh> | 5 | #include <qpdf/DLL.hh> |
| 7 | -#include <qpdf/QEXC.hh> | ||
| 8 | #include <qpdf/qpdf-config.h> | 6 | #include <qpdf/qpdf-config.h> |
| 9 | #ifdef HAVE_INTTYPES_H | 7 | #ifdef HAVE_INTTYPES_H |
| 10 | # include <inttypes.h> | 8 | # include <inttypes.h> |
| @@ -26,8 +24,7 @@ class MD5 | @@ -26,8 +24,7 @@ class MD5 | ||
| 26 | 24 | ||
| 27 | // encodes file and finalizes | 25 | // encodes file and finalizes |
| 28 | DLL_EXPORT | 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 | // appends string to current md5 object | 29 | // appends string to current md5 object |
| 33 | DLL_EXPORT | 30 | DLL_EXPORT |
libqpdf/qpdf/PCRE.hh
| @@ -10,9 +10,9 @@ | @@ -10,9 +10,9 @@ | ||
| 10 | #endif | 10 | #endif |
| 11 | #include <pcre.h> | 11 | #include <pcre.h> |
| 12 | #include <string> | 12 | #include <string> |
| 13 | +#include <stdexcept> | ||
| 13 | 14 | ||
| 14 | #include <qpdf/DLL.hh> | 15 | #include <qpdf/DLL.hh> |
| 15 | -#include <qpdf/QEXC.hh> | ||
| 16 | 16 | ||
| 17 | // Note: this class does not encapsulate all features of the PCRE | 17 | // Note: this class does not encapsulate all features of the PCRE |
| 18 | // package -- only those that I actually need right now are here. | 18 | // package -- only those that I actually need right now are here. |
| @@ -20,18 +20,9 @@ | @@ -20,18 +20,9 @@ | ||
| 20 | class PCRE | 20 | class PCRE |
| 21 | { | 21 | { |
| 22 | public: | 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 | // This is thrown when an attempt is made to access a non-existent | 23 | // This is thrown when an attempt is made to access a non-existent |
| 33 | // back reference. | 24 | // back reference. |
| 34 | - class NoBackref: public Exception | 25 | + class NoBackref: public std::logic_error |
| 35 | { | 26 | { |
| 36 | public: | 27 | public: |
| 37 | DLL_EXPORT | 28 | DLL_EXPORT |
| @@ -65,14 +56,13 @@ class PCRE | @@ -65,14 +56,13 @@ class PCRE | ||
| 65 | 56 | ||
| 66 | // see getMatch flags below | 57 | // see getMatch flags below |
| 67 | DLL_EXPORT | 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 | DLL_EXPORT | 60 | DLL_EXPORT |
| 71 | - void getOffsetLength(int n, int& offset, int& length) throw(Exception); | 61 | + void getOffsetLength(int n, int& offset, int& length); |
| 72 | DLL_EXPORT | 62 | DLL_EXPORT |
| 73 | - int getOffset(int n) throw(Exception); | 63 | + int getOffset(int n); |
| 74 | DLL_EXPORT | 64 | DLL_EXPORT |
| 75 | - int getLength(int n) throw(Exception); | 65 | + int getLength(int n); |
| 76 | 66 | ||
| 77 | // nMatches returns the number of available matches including | 67 | // nMatches returns the number of available matches including |
| 78 | // match 0 which is the whole string. In other words, if you | 68 | // match 0 which is the whole string. In other words, if you |
| @@ -105,14 +95,13 @@ class PCRE | @@ -105,14 +95,13 @@ class PCRE | ||
| 105 | // The value passed in as options is passed to pcre_exec. See man | 95 | // The value passed in as options is passed to pcre_exec. See man |
| 106 | // pcreapi for details. | 96 | // pcreapi for details. |
| 107 | DLL_EXPORT | 97 | DLL_EXPORT |
| 108 | - PCRE(char const* pattern, int options = 0) throw(Exception); | 98 | + PCRE(char const* pattern, int options = 0); |
| 109 | DLL_EXPORT | 99 | DLL_EXPORT |
| 110 | ~PCRE(); | 100 | ~PCRE(); |
| 111 | 101 | ||
| 112 | DLL_EXPORT | 102 | DLL_EXPORT |
| 113 | Match match(char const* subject, int options = 0, int startoffset = 0, | 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 | DLL_EXPORT | 106 | DLL_EXPORT |
| 118 | static void test(int n = 0); | 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,21 +19,6 @@ | ||
| 19 | class Pl_PNGFilter: public Pipeline | 19 | class Pl_PNGFilter: public Pipeline |
| 20 | { | 20 | { |
| 21 | public: | 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 | // Encoding is not presently supported | 22 | // Encoding is not presently supported |
| 38 | enum action_e { a_encode, a_decode }; | 23 | enum action_e { a_encode, a_decode }; |
| 39 | 24 |
libqpdf/qpdf/Pl_QPDFTokenizer.hh
libqpdf/qpdf/Pl_RC4.hh
| 1 | - | ||
| 2 | #ifndef __PL_RC4_HH__ | 1 | #ifndef __PL_RC4_HH__ |
| 3 | #define __PL_RC4_HH__ | 2 | #define __PL_RC4_HH__ |
| 4 | 3 | ||
| @@ -9,21 +8,6 @@ | @@ -9,21 +8,6 @@ | ||
| 9 | class Pl_RC4: public Pipeline | 8 | class Pl_RC4: public Pipeline |
| 10 | { | 9 | { |
| 11 | public: | 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 | static int const def_bufsize = 65536; | 11 | static int const def_bufsize = 65536; |
| 28 | 12 | ||
| 29 | // key_len of -1 means treat key_data as a null-terminated string | 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,9 +105,9 @@ int main(int argc, char* argv[]) | ||
| 105 | { | 105 | { |
| 106 | run(filename); | 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 | return 0; | 112 | return 0; |
| 113 | } | 113 | } |
libtests/md5.cc
libtests/pcre.cc
| 1 | - | ||
| 2 | #include <qpdf/PCRE.hh> | 1 | #include <qpdf/PCRE.hh> |
| 3 | #include <iostream> | 2 | #include <iostream> |
| 4 | #include <string.h> | 3 | #include <string.h> |
| @@ -12,7 +11,7 @@ int main(int argc, char* argv[]) | @@ -12,7 +11,7 @@ int main(int argc, char* argv[]) | ||
| 12 | PCRE("^([\\p{L}]+)", PCRE_UTF8); | 11 | PCRE("^([\\p{L}]+)", PCRE_UTF8); |
| 13 | std::cout << "1" << std::endl; | 12 | std::cout << "1" << std::endl; |
| 14 | } | 13 | } |
| 15 | - catch (PCRE::Exception& e) | 14 | + catch (std::exception& e) |
| 16 | { | 15 | { |
| 17 | std::cout << "0" << std::endl; | 16 | std::cout << "0" << std::endl; |
| 18 | } | 17 | } |
libtests/png_filter.cc
| 1 | - | ||
| 2 | #include <qpdf/Pl_PNGFilter.hh> | 1 | #include <qpdf/Pl_PNGFilter.hh> |
| 3 | #include <qpdf/Pl_StdioFile.hh> | 2 | #include <qpdf/Pl_StdioFile.hh> |
| 4 | 3 | ||
| @@ -79,9 +78,9 @@ int main(int argc, char* argv[]) | @@ -79,9 +78,9 @@ int main(int argc, char* argv[]) | ||
| 79 | { | 78 | { |
| 80 | run(filename, encode, columns); | 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 | return 0; | 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
| @@ -5,7 +5,7 @@ data: 1234567890abcdefghij | @@ -5,7 +5,7 @@ data: 1234567890abcdefghij | ||
| 5 | count: 32 | 5 | count: 32 |
| 6 | size: 11 | 6 | size: 11 |
| 7 | data: qwertyuiop | 7 | data: qwertyuiop |
| 8 | -INTERNAL ERROR: Pl_Buffer::getBuffer() called when not ready | 8 | +Pl_Buffer::getBuffer() called when not ready |
| 9 | size: 9 | 9 | size: 9 |
| 10 | data: mooquack | 10 | data: mooquack |
| 11 | done | 11 | done |
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,11 +4,11 @@ | ||
| 4 | 3.141590 | 4 | 3.141590 |
| 5 | 3.142 | 5 | 3.142 |
| 6 | 1000.123000 | 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 | one | 12 | one |
| 13 | 7 | 13 | 7 |
| 14 | compare okay | 14 | compare okay |
libtests/qutil.cc
| 1 | - | ||
| 2 | #include <iostream> | 1 | #include <iostream> |
| 3 | #include <stdio.h> | 2 | #include <stdio.h> |
| 4 | #include <sys/types.h> | 3 | #include <sys/types.h> |
| @@ -27,9 +26,9 @@ void string_conversion_test() | @@ -27,9 +26,9 @@ void string_conversion_test() | ||
| 27 | // int_to_string bounds error | 26 | // int_to_string bounds error |
| 28 | std::cout << QUtil::int_to_string(1, 50) << std::endl; | 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 | try | 34 | try |
| @@ -37,9 +36,9 @@ void string_conversion_test() | @@ -37,9 +36,9 @@ void string_conversion_test() | ||
| 37 | // QUtil::int_to_string bounds error | 36 | // QUtil::int_to_string bounds error |
| 38 | std::cout << QUtil::int_to_string(1, -50) << std::endl; | 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 | try | 44 | try |
| @@ -47,9 +46,9 @@ void string_conversion_test() | @@ -47,9 +46,9 @@ void string_conversion_test() | ||
| 47 | // QUtil::int_to_string bounds error | 46 | // QUtil::int_to_string bounds error |
| 48 | std::cout << QUtil::int_to_string(-1, 49) << std::endl; | 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,9 +57,9 @@ void string_conversion_test() | ||
| 58 | // QUtil::double_to_string bounds error | 57 | // QUtil::double_to_string bounds error |
| 59 | std::cout << QUtil::double_to_string(3.14159, 1024) << std::endl; | 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 | try | 65 | try |
| @@ -68,9 +67,9 @@ void string_conversion_test() | @@ -68,9 +67,9 @@ void string_conversion_test() | ||
| 68 | // QUtil::double_to_string bounds error | 67 | // QUtil::double_to_string bounds error |
| 69 | std::cout << QUtil::double_to_string(1000.0, 95) << std::endl; | 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 | std::string embedded_null = "one"; | 75 | std::string embedded_null = "one"; |
| @@ -101,9 +100,9 @@ void os_wrapper_test() | @@ -101,9 +100,9 @@ void os_wrapper_test() | ||
| 101 | std::cout << "after open" << std::endl; | 100 | std::cout << "after open" << std::endl; |
| 102 | (void) close(fd); | 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,9 +117,9 @@ void fopen_wrapper_test() | ||
| 118 | std::cout << "after fopen" << std::endl; | 117 | std::cout << "after fopen" << std::endl; |
| 119 | (void) fclose(f); | 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,7 +170,7 @@ void to_utf8_test() | ||
| 171 | { | 170 | { |
| 172 | print_utf8(0x80000000UL); | 171 | print_utf8(0x80000000UL); |
| 173 | } | 172 | } |
| 174 | - catch (QEXC::General& e) | 173 | + catch (std::runtime_error& e) |
| 175 | { | 174 | { |
| 176 | std::cout << "0x80000000: " << e.what() << std::endl; | 175 | std::cout << "0x80000000: " << e.what() << std::endl; |
| 177 | } | 176 | } |
libtests/rc4.cc
qpdf/qpdf.cc
| 1 | - | ||
| 2 | #include <iostream> | 1 | #include <iostream> |
| 3 | #include <string.h> | 2 | #include <string.h> |
| 4 | #include <stdlib.h> | 3 | #include <stdlib.h> |
| @@ -943,7 +942,7 @@ int main(int argc, char* argv[]) | @@ -943,7 +942,7 @@ int main(int argc, char* argv[]) | ||
| 943 | } | 942 | } |
| 944 | else | 943 | else |
| 945 | { | 944 | { |
| 946 | - throw QEXC::Internal("bad encryption keylen"); | 945 | + throw std::logic_error("bad encryption keylen"); |
| 947 | } | 946 | } |
| 948 | } | 947 | } |
| 949 | if (linearize) | 948 | if (linearize) |
qpdf/test_driver.cc
| @@ -284,8 +284,8 @@ void runtest(int n, char const* filename) | @@ -284,8 +284,8 @@ void runtest(int n, char const* filename) | ||
| 284 | } | 284 | } |
| 285 | else | 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 | std::cout << "test " << n << " done" << std::endl; | 291 | std::cout << "test " << n << " done" << std::endl; |