removed qexc; non-compatible ABI change

git-svn-id: svn+q:///qpdf/trunk@709 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
Jay Berkenbilt 2009-09-26 18:36:04 +00:00
parent 64546cfa0d
commit f3d7c26de1
89 changed files with 251 additions and 651 deletions

View File

@ -1,3 +1,8 @@
2009-09-26 Jay Berkenbilt <ejb@ql.org>
* Removed all references to QEXC; now using std::runtime_error and
std::logic_error and their subclasses for all exceptions.
2009-05-03 Jay Berkenbilt <ejb@ql.org>
* 2.0.6. release

5
TODO
View File

@ -1,6 +1,11 @@
2.1
===
* Be able to trap I/O errors separately from other errors; especially
be able to separate errors that the user can fix (like permission
errors) from errors that they probably can't fix like corrupted PDF
files, unsupported filters, or internal errors.
* Add ability to create new streams or replace stream data. Consider
stream data sources to include a file and offset, a buffer, or a
some kind of callback mechanism. Find messages exchanged with

View File

@ -31,27 +31,11 @@
#define __PIPELINE_HH__
#include <qpdf/DLL.hh>
#include <qpdf/QEXC.hh>
#include <string>
class Pipeline
{
public:
class Exception: public QEXC::General
{
public:
DLL_EXPORT
Exception(std::string const& message) :
QEXC::General(message)
{
}
DLL_EXPORT
virtual ~Exception() throw()
{
}
};
DLL_EXPORT
Pipeline(char const* identifier, Pipeline* next);

View File

@ -15,21 +15,6 @@
class Pl_Flate: public Pipeline
{
public:
class Exception: public Pipeline::Exception
{
public:
DLL_EXPORT
Exception(std::string const& message) :
Pipeline::Exception(message)
{
}
DLL_EXPORT
virtual ~Exception() throw ()
{
}
};
static int const def_bufsize = 65536;
enum action_e { a_inflate, a_deflate };

View File

@ -21,21 +21,6 @@
class Pl_StdioFile: public Pipeline
{
public:
class Exception: public Pipeline::Exception
{
public:
DLL_EXPORT
Exception(std::string const& message) :
Pipeline::Exception(message)
{
}
DLL_EXPORT
virtual ~Exception() throw ()
{
}
};
// f is externally maintained; this class just writes to and
// flushes it. It does not close it.
DLL_EXPORT

View File

@ -1,135 +0,0 @@
// Copyright (c) 2005-2009 Jay Berkenbilt
//
// This file is part of qpdf. This software may be distributed under
// the terms of version 2 of the Artistic License which may be found
// in the source distribution. It is provided "as is" without express
// or implied warranty.
#ifndef __QEXC_HH__
#define __QEXC_HH__
#include <qpdf/DLL.hh>
#include <string>
#include <exception>
#include <errno.h>
namespace QEXC
{
// This namespace contains all exception classes used by the
// library.
// The class hierarchy is as follows:
// std::exception
// |
// +-> QEXC::Base
// |
// +-> QEXC::General
// |
// +-> QEXC::Internal
// QEXC::General is the base class of all standard user-defined
// exceptions and "expected" error conditions raised by QClass.
// Applications or libraries using QClass are encouraged to derive
// their own exceptions from these classes if they wish. It is
// entirely reasonable for code to catch QEXC::General or specific
// subclasses of it as part of normal error handling.
// QEXC::Internal is reserved for internal errors. These should
// be used only for situations that indicate a likely bug in the
// software itself. This may include improper use of a library
// function. Operator errors should not be able to cause Internal
// errors. (There may be some exceptions to this such as users
// invoking programs that were intended only to be invoked by
// other programs.) QEXC::Internal should generally not be
// trapped except in terminate handlers or top-level exception
// handlers which will want to translate them into error messages
// and cause the program to exit. Such top-level handlers may
// want to catch std::exception instead.
// All subclasses of QEXC::Base implement a const unparse() method
// which returns a std::string const&. They also override
// std::exception::what() to return a char* with the same value.
// unparse() should be implemented in such a way that a program
// catching QEXC::Base or std::exception can use the text returned
// by unparse() (or what()) without any exception-specific
// adornment. (The program may prefix the program name or other
// general information.) Note that std::exception::what() is a
// const method that returns a const char*. For this reason, it
// is essential that unparse() return a const reference to a
// string so that what() can be implemented by calling unparse().
// This means that the string that unparse() returns a reference
// to must not be allocated on the stack in the call to unparse().
// The recommended way to do this is for derived exception classes
// to store their string descriptions by calling the protected
// setMessage() method and then to not override unparse().
class Base: public std::exception
{
// This is the common base class for all exceptions in qclass.
// Application/library code should not generally catch this
// directly. See above for caveats.
public:
DLL_EXPORT
Base();
DLL_EXPORT
Base(std::string const& message);
DLL_EXPORT
virtual ~Base() throw() {}
DLL_EXPORT
virtual std::string const& unparse() const;
DLL_EXPORT
virtual const char* what() const throw();
protected:
DLL_EXPORT
void setMessage(std::string const& message);
private:
std::string message;
};
class General: public Base
{
// This is the base class for normal user/library-defined
// error conditions.
public:
DLL_EXPORT
General();
DLL_EXPORT
General(std::string const& message);
DLL_EXPORT
virtual ~General() throw() {};
};
// Note that Internal is not derived from General. Internal
// errors are too severe. We don't want internal errors
// accidentally trapped as part of QEXC::General. If you are
// going to deal with internal errors, you have to do so
// explicitly.
class Internal: public Base
{
public:
DLL_EXPORT
Internal(std::string const& message);
DLL_EXPORT
virtual ~Internal() throw() {};
};
class System: public General
{
public:
DLL_EXPORT
System(std::string const& prefix, int sys_errno);
DLL_EXPORT
virtual ~System() throw() {};
DLL_EXPORT
int getErrno() const;
private:
int sys_errno;
};
};
#endif // __QEXC_HH__

View File

@ -8,9 +8,10 @@
#ifndef __QPDFEXC_HH__
#define __QPDFEXC_HH__
#include <qpdf/QEXC.hh>
#include <qpdf/DLL.hh>
#include <stdexcept>
class QPDFExc: public QEXC::General
class QPDFExc: public std::runtime_error
{
public:
DLL_EXPORT

View File

@ -8,13 +8,13 @@
#ifndef __QUTIL_HH__
#define __QUTIL_HH__
#include <qpdf/DLL.hh>
#include <string>
#include <list>
#include <stdexcept>
#include <stdio.h>
#include <sys/stat.h>
#include <qpdf/QEXC.hh>
namespace QUtil
{
// This is a collection of useful utility functions that don't
@ -24,15 +24,25 @@ namespace QUtil
DLL_EXPORT
std::string double_to_string(double, int decimal_places = 0);
// If status is -1, convert the current value of errno to a
// QEXC::System exception. Otherwise, return status.
// Throw std::runtime_error with a string formed by appending to
// "description: " the standard string corresponding to the
// current value of errno.
DLL_EXPORT
int os_wrapper(std::string const& description, int status)
throw (QEXC::System);
void throw_system_error(std::string const& description);
// The status argument is assumed to be the return value of a
// standard library call that sets errno when it fails. If status
// is -1, convert the current value of errno to a
// std::runtime_error that includes the standard error string.
// Otherwise, return status.
DLL_EXPORT
FILE* fopen_wrapper(std::string const&, FILE*)
throw (QEXC::System);
int os_wrapper(std::string const& description, int status);
// The FILE* argument is assumed to be the return of fopen. If
// null, throw std::runtime_error. Otherwise, return the FILE*
// argument.
DLL_EXPORT
FILE* fopen_wrapper(std::string const&, FILE*);
DLL_EXPORT
char* copy_string(std::string const&);

View File

@ -38,7 +38,8 @@ BitStream::skipToNextByte()
unsigned int bits_to_skip = bit_offset + 1;
if (bits_available < bits_to_skip)
{
throw QEXC::Internal("overflow skipping to next byte in bitstream");
throw std::logic_error(
"INTERNAL ERROR: overflow skipping to next byte in bitstream");
}
bit_offset = 7;
++p;

View File

@ -1,5 +1,3 @@
#include <qpdf/BitWriter.hh>
// See comments in bits.cc

View File

@ -1,4 +1,3 @@
#include <qpdf/Buffer.hh>
#include <string.h>

View File

@ -28,6 +28,7 @@
/////////////////////////////////////////////////////////////////////////
#include <qpdf/MD5.hh>
#include <qpdf/QUtil.hh>
#include <stdio.h>
#include <memory.h>
@ -330,15 +331,12 @@ void MD5::encodeDataIncrementally(char const* data, int len)
DLL_EXPORT
void MD5::encodeFile(char const *filename, int up_to_size)
throw (QEXC::System)
{
FILE *file;
unsigned char buffer[1024];
if ((file = fopen (filename, "rb")) == NULL)
{
throw QEXC::System(std::string("MD5: can't open ") + filename, errno);
}
FILE *file = QUtil::fopen_wrapper(
std::string("MD5: open ") + filename,
fopen(filename, "rb"));
int len;
int so_far = 0;
@ -365,7 +363,8 @@ void MD5::encodeFile(char const *filename, int up_to_size)
// Assume, perhaps incorrectly, that errno was set by the
// underlying call to read....
(void) fclose(file);
throw QEXC::System(std::string("MD5: read error on ") + filename, errno);
QUtil::throw_system_error(
std::string("MD5: read error on ") + filename);
}
(void) fclose(file);
@ -446,7 +445,7 @@ MD5::checkFileChecksum(char const* const checksum,
std::string actual_checksum = getFileChecksum(filename, up_to_size);
result = (checksum == actual_checksum);
}
catch (QEXC::System)
catch (std::runtime_error)
{
// Ignore -- return false
}

View File

@ -1,19 +1,13 @@
#include <qpdf/PCRE.hh>
#include <qpdf/QUtil.hh>
#include <stdexcept>
#include <iostream>
#include <string.h>
DLL_EXPORT
PCRE::Exception::Exception(std::string const& message)
{
this->setMessage("PCRE error: " + message);
}
DLL_EXPORT
PCRE::NoBackref::NoBackref() :
Exception("no match")
std::logic_error("PCRE error: no match")
{
}
@ -87,7 +81,6 @@ PCRE::Match::operator bool()
DLL_EXPORT
std::string
PCRE::Match::getMatch(int n, int flags)
throw(QEXC::General, Exception)
{
// This method used to be implemented in terms of
// pcre_get_substring, but that function gives you an empty string
@ -116,7 +109,7 @@ PCRE::Match::getMatch(int n, int flags)
DLL_EXPORT
void
PCRE::Match::getOffsetLength(int n, int& offset, int& length) throw(Exception)
PCRE::Match::getOffsetLength(int n, int& offset, int& length)
{
if ((this->nmatches < 0) ||
(n > this->nmatches - 1) ||
@ -130,7 +123,7 @@ PCRE::Match::getOffsetLength(int n, int& offset, int& length) throw(Exception)
DLL_EXPORT
int
PCRE::Match::getOffset(int n) throw(Exception)
PCRE::Match::getOffset(int n)
{
int offset;
int length;
@ -140,7 +133,7 @@ PCRE::Match::getOffset(int n) throw(Exception)
DLL_EXPORT
int
PCRE::Match::getLength(int n) throw(Exception)
PCRE::Match::getLength(int n)
{
int offset;
int length;
@ -156,7 +149,7 @@ PCRE::Match::nMatches() const
}
DLL_EXPORT
PCRE::PCRE(char const* pattern, int options) throw (PCRE::Exception)
PCRE::PCRE(char const* pattern, int options)
{
char const *errptr;
int erroffset;
@ -171,7 +164,7 @@ PCRE::PCRE(char const* pattern, int options) throw (PCRE::Exception)
" failed at offset " +
QUtil::int_to_string(erroffset) + ": " +
errptr);
throw Exception(message);
throw std::runtime_error("PCRE error: " + message);
}
}
@ -184,7 +177,6 @@ PCRE::~PCRE()
DLL_EXPORT
PCRE::Match
PCRE::match(char const* subject, int options, int startoffset, int size)
throw (QEXC::General, Exception)
{
if (size == -1)
{
@ -210,12 +202,12 @@ PCRE::match(char const* subject, int options, int startoffset, int size)
case PCRE_ERROR_BADOPTION:
message = "bad option passed to PCRE::match()";
throw Exception(message);
throw std::logic_error(message);
break;
case PCRE_ERROR_NOMEMORY:
message = "insufficient memory";
throw Exception(message);
throw std::runtime_error(message);
break;
case PCRE_ERROR_NULL:
@ -223,7 +215,7 @@ PCRE::match(char const* subject, int options, int startoffset, int size)
case PCRE_ERROR_UNKNOWN_NODE:
default:
message = "pcre_exec returned " + QUtil::int_to_string(status);
throw QEXC::Internal(message);
throw std::logic_error(message);
}
}
@ -258,9 +250,9 @@ PCRE::test(int n)
{
PCRE pcre1("a**");
}
catch (Exception& e)
catch (std::exception& e)
{
std::cout << e.unparse() << std::endl;
std::cout << e.what() << std::endl;
}
PCRE pcre2("^([^\\s:]*)\\s*:\\s*(.*?)\\s*$");
@ -281,17 +273,17 @@ PCRE::test(int n)
{
std::cout << m2.getMatch(3) << std::endl;
}
catch (Exception& e)
catch (std::exception& e)
{
std::cout << e.unparse() << std::endl;
std::cout << e.what() << std::endl;
}
try
{
std::cout << m2.getOffset(3) << std::endl;
}
catch (Exception& e)
catch (std::exception& e)
{
std::cout << e.unparse() << std::endl;
std::cout << e.what() << std::endl;
}
}
PCRE pcre3("^(a+)(b+)?$");
@ -312,9 +304,9 @@ PCRE::test(int n)
std::cout << "can't see this" << std::endl;
}
}
catch (Exception& e)
catch (std::exception& e)
{
std::cout << e.unparse() << std::endl;
std::cout << e.what() << std::endl;
}
// backref: 1 2 3 4 5
@ -370,8 +362,8 @@ PCRE::test(int n)
}
}
}
catch (QEXC::General& e)
catch (std::exception& e)
{
std::cout << "unexpected exception: " << e.unparse() << std::endl;
std::cout << "unexpected exception: " << e.what() << std::endl;
}
}

View File

@ -1,6 +1,5 @@
#include <qpdf/Pipeline.hh>
#include <stdexcept>
DLL_EXPORT
Pipeline::Pipeline(char const* identifier, Pipeline* next) :
@ -19,7 +18,7 @@ Pipeline::getNext(bool allow_null)
{
if ((next == 0) && (! allow_null))
{
throw Exception(
throw std::logic_error(
this->identifier +
": Pipeline::getNext() called on pipeline with no next");
}

View File

@ -1,6 +1,6 @@
#include <qpdf/Pl_ASCII85Decoder.hh>
#include <qpdf/QEXC.hh>
#include <qpdf/QTC.hh>
#include <stdexcept>
#include <string.h>
DLL_EXPORT
@ -40,7 +40,7 @@ Pl_ASCII85Decoder::write(unsigned char* buf, int len)
}
else
{
throw QEXC::General(
throw std::runtime_error(
"broken end-of-data sequence in base 85 data");
}
}
@ -65,7 +65,7 @@ Pl_ASCII85Decoder::write(unsigned char* buf, int len)
case 'z':
if (pos != 0)
{
throw QEXC::General(
throw std::runtime_error(
"unexpected z during base 85 decode");
}
else
@ -78,8 +78,8 @@ Pl_ASCII85Decoder::write(unsigned char* buf, int len)
default:
if ((buf[i] < 33) || (buf[i] > 117))
{
throw QEXC::General
("character out of range during base 85 decode");
throw std::runtime_error(
"character out of range during base 85 decode");
}
else
{

View File

@ -1,6 +1,6 @@
#include <qpdf/Pl_ASCIIHexDecoder.hh>
#include <qpdf/QEXC.hh>
#include <qpdf/QTC.hh>
#include <stdexcept>
#include <string.h>
#include <ctype.h>
@ -61,8 +61,9 @@ Pl_ASCIIHexDecoder::write(unsigned char* buf, int len)
char t[2];
t[0] = ch;
t[1] = 0;
throw QEXC::General(
std::string("character out of range during base Hex decode: ") + t);
throw std::runtime_error(
std::string("character out of range"
" during base Hex decode: ") + t);
}
break;
}

View File

@ -1,6 +1,5 @@
#include <qpdf/Pl_Buffer.hh>
#include <qpdf/QEXC.hh>
#include <stdexcept>
#include <assert.h>
#include <string.h>
@ -50,7 +49,7 @@ Pl_Buffer::getBuffer()
{
if (! this->ready)
{
throw QEXC::Internal("Pl_Buffer::getBuffer() called when not ready");
throw std::logic_error("Pl_Buffer::getBuffer() called when not ready");
}
Buffer* b = new Buffer(this->total_size);

View File

@ -1,4 +1,3 @@
#include <qpdf/Pl_Count.hh>
DLL_EXPORT

View File

@ -1,4 +1,3 @@
#include <qpdf/Pl_Discard.hh>
// Exercised in md5 test suite

View File

@ -1,4 +1,3 @@
#include <qpdf/Pl_Flate.hh>
#include <qpdf/QUtil.hh>
@ -38,7 +37,7 @@ Pl_Flate::write(unsigned char* data, int len)
{
if (this->outbuf == 0)
{
throw Exception(
throw std::logic_error(
this->identifier +
": Pl_Flate: write() called after finish() called");
}
@ -197,6 +196,6 @@ Pl_Flate::checkError(char const* prefix, int error_code)
}
}
throw Exception(msg);
throw std::runtime_error(msg);
}
}

View File

@ -1,7 +1,7 @@
#include <qpdf/Pl_LZWDecoder.hh>
#include <qpdf/QEXC.hh>
#include <qpdf/QTC.hh>
#include <stdexcept>
#include <string.h>
#include <assert.h>
@ -185,7 +185,7 @@ Pl_LZWDecoder::handleCode(int code)
unsigned int idx = code - 258;
if (idx > table_size)
{
throw QEXC::General("LZWDecoder: bad code received");
throw std::runtime_error("LZWDecoder: bad code received");
}
else if (idx == table_size)
{
@ -204,7 +204,7 @@ Pl_LZWDecoder::handleCode(int code)
unsigned int new_idx = 258 + table_size;
if (new_idx == 4096)
{
throw QEXC::General("LZWDecoder: table full");
throw std::runtime_error("LZWDecoder: table full");
}
addToTable(next);
unsigned int change_idx = new_idx + code_change_delta;

View File

@ -1,7 +1,5 @@
#include <qpdf/Pl_MD5.hh>
#include <qpdf/QEXC.hh>
#include <stdexcept>
DLL_EXPORT
Pl_MD5::Pl_MD5(char const* identifier, Pipeline* next) :
@ -42,7 +40,8 @@ Pl_MD5::getHexDigest()
{
if (this->in_progress)
{
throw QEXC::General("digest requested for in-progress MD5 Pipeline");
throw std::logic_error(
"digest requested for in-progress MD5 Pipeline");
}
return this->md5.unparse();
}

View File

@ -1,5 +1,5 @@
#include <qpdf/Pl_PNGFilter.hh>
#include <stdexcept>
#include <string.h>
DLL_EXPORT
@ -85,7 +85,7 @@ Pl_PNGFilter::decodeRow()
break;
case 1: // sub
throw Exception("sub filter not implemented");
throw std::logic_error("sub filter not implemented");
break;
case 2: // up
@ -96,11 +96,11 @@ Pl_PNGFilter::decodeRow()
break;
case 3: // average
throw Exception("average filter not implemented");
throw std::logic_error("average filter not implemented");
break;
case 4: // Paeth
throw Exception("Paeth filter not implemented");
throw std::logic_error("Paeth filter not implemented");
break;
default:

View File

@ -1,7 +1,7 @@
#include <qpdf/Pl_QPDFTokenizer.hh>
#include <qpdf/QPDF_String.hh>
#include <qpdf/QPDF_Name.hh>
#include <stdexcept>
#include <string.h>
Pl_QPDFTokenizer::Pl_QPDFTokenizer(char const* identifier, Pipeline* next) :
@ -134,8 +134,9 @@ Pl_QPDFTokenizer::checkUnread()
processChar(this->char_to_unread);
if (this->unread_char)
{
throw QEXC::Internal("unread_char still true after processing "
"unread character");
throw std::logic_error(
"INTERNAL ERROR: unread_char still true after processing "
"unread character");
}
}
}

View File

@ -1,6 +1,4 @@
#include <qpdf/Pl_RC4.hh>
#include <qpdf/QUtil.hh>
DLL_EXPORT
@ -30,7 +28,7 @@ Pl_RC4::write(unsigned char* data, int len)
{
if (this->outbuf == 0)
{
throw Exception(
throw std::logic_error(
this->identifier +
": Pl_RC4: write() called after finish() called");
}

View File

@ -1,6 +1,6 @@
#include <qpdf/Pl_StdioFile.hh>
#include <qpdf/QUtil.hh>
#include <stdexcept>
#include <errno.h>
DLL_EXPORT
@ -25,8 +25,8 @@ Pl_StdioFile::write(unsigned char* buf, int len)
so_far = fwrite(buf, 1, len, this->file);
if (so_far == 0)
{
throw QEXC::System(this->identifier + ": Pl_StdioFile::write",
errno);
QUtil::throw_system_error(
this->identifier + ": Pl_StdioFile::write");
}
else
{
@ -46,7 +46,8 @@ Pl_StdioFile::finish()
}
else
{
throw QEXC::Internal(this->identifier +
": Pl_StdioFile::finish: stream already closed");
throw std::logic_error(
this->identifier +
": Pl_StdioFile::finish: stream already closed");
}
}

View File

@ -1,77 +0,0 @@
#include <qpdf/QEXC.hh>
#include <string.h>
#include <errno.h>
DLL_EXPORT
QEXC::Base::Base()
{
// nothing needed
}
DLL_EXPORT
QEXC::Base::Base(std::string const& message) :
message(message)
{
// nothing needed
}
DLL_EXPORT
std::string const&
QEXC::Base::unparse() const
{
return this->message;
}
DLL_EXPORT
void
QEXC::Base::setMessage(std::string const& message)
{
this->message = message;
}
DLL_EXPORT
const char*
QEXC::Base::what() const throw()
{
// Since unparse() returns a const string reference, its
// implementors must arrange to have it return a reference to a
// string that is not going to disappear. It is therefore safe
// for us to return it's c_str() pointer.
return this->unparse().c_str();
}
DLL_EXPORT
QEXC::General::General()
{
// nothing needed
}
DLL_EXPORT
QEXC::General::General(std::string const& message) :
Base(message)
{
// nothing needed
}
DLL_EXPORT
QEXC::System::System(std::string const& prefix, int sys_errno)
{
// Note: using sys_errno in case errno is a macro.
this->sys_errno = sys_errno;
this->setMessage(prefix + ": " + strerror(sys_errno));
}
DLL_EXPORT
int
QEXC::System::getErrno() const
{
return this->sys_errno;
}
DLL_EXPORT
QEXC::Internal::Internal(std::string const& message) :
Base("INTERNAL ERROR: " + message)
{
// nothing needed
}

View File

@ -1,4 +1,3 @@
#include <qpdf/QPDF.hh>
#include <vector>
@ -197,7 +196,8 @@ QPDF::BufferInputSource::seek(off_t offset, int whence)
break;
default:
throw QEXC::Internal("invalid argument to BufferInputSource::seek");
throw std::logic_error(
"INTERNAL ERROR: invalid argument to BufferInputSource::seek");
break;
}
}
@ -392,7 +392,7 @@ QPDF::parse()
void
QPDF::warn(QPDFExc const& e)
{
this->warnings.push_back(e.unparse());
this->warnings.push_back(e.what());
if (! this->suppress_warnings)
{
std::cerr << "WARNING: " << this->warnings.back() << std::endl;
@ -956,8 +956,8 @@ QPDF::showXRefTable()
break;
default:
throw QEXC::Internal("unknown cross-reference table type while"
" showing xref_table");
throw std::logic_error("unknown cross-reference table type while"
" showing xref_table");
break;
}
std::cout << std::endl;
@ -988,7 +988,8 @@ QPDF::readObjectInternal(InputSource* input,
// Although dictionaries and arrays arbitrarily nest, these
// variables indicate what is at the top of the stack right
// now, so they can, by definition, never both be true.
throw QEXC::Internal("readObjectInternal: in_dict && in_array");
throw std::logic_error(
"INTERNAL ERROR: readObjectInternal: in_dict && in_array");
}
QPDFObjectHandle object;
@ -1121,9 +1122,10 @@ QPDF::readObjectInternal(InputSource* input,
}
else if (! object.isInitialized())
{
throw QEXC::Internal(std::string("uninitialized object (token = ") +
QUtil::int_to_string(token.getType()) +
", " + token.getValue() + ")");
throw std::logic_error(
"INTERNAL ERROR: uninitialized object (token = " +
QUtil::int_to_string(token.getType()) +
", " + token.getValue() + ")");
}
else
{
@ -1846,13 +1848,13 @@ QPDF::pipeStreamData(int objid, int generation,
pipeline->write((unsigned char*)buf, len);
}
}
catch (QEXC::General& e)
catch (std::runtime_error& e)
{
QTC::TC("qpdf", "QPDF decoding error warning");
warn(QPDFExc(this->file.getName(), this->file.getLastOffset(),
"error decoding stream data for object " +
QUtil::int_to_string(objid) + " " +
QUtil::int_to_string(generation) + ": " + e.unparse()));
QUtil::int_to_string(generation) + ": " + e.what()));
}
pipeline->finish();
}

View File

@ -1,19 +1,17 @@
#include <qpdf/QPDFExc.hh>
#include <qpdf/QUtil.hh>
DLL_EXPORT
QPDFExc::QPDFExc(std::string const& message) :
QEXC::General(message)
std::runtime_error(message)
{
}
DLL_EXPORT
QPDFExc::QPDFExc(std::string const& filename, int offset,
std::string const& message) :
QEXC::General(filename + ": offset " + QUtil::int_to_string(offset) +
": " + message)
std::runtime_error(filename + ": offset " + QUtil::int_to_string(offset) +
": " + message)
{
}

View File

@ -1,2 +1 @@
#include <qpdf/QPDFObject.hh>

View File

@ -1,4 +1,3 @@
#include <qpdf/QPDFObjectHandle.hh>
#include <qpdf/QPDF.hh>
@ -13,9 +12,9 @@
#include <qpdf/QPDF_Stream.hh>
#include <qpdf/QTC.hh>
#include <qpdf/QEXC.hh>
#include <qpdf/QUtil.hh>
#include <stdexcept>
#include <stdlib.h>
DLL_EXPORT
@ -114,7 +113,7 @@ QPDFObjectHandle::getNumericValue()
}
else
{
throw QEXC::Internal("getNumericValue called for non-numeric object");
throw std::logic_error("getNumericValue called for non-numeric object");
}
return result;
}
@ -416,9 +415,10 @@ QPDFObjectHandle::getPageContents()
}
else
{
throw QEXC::General("unknown item type while inspecting "
"element of /Contents array in page "
"dictionary");
throw std::runtime_error(
"unknown item type while inspecting "
"element of /Contents array in page "
"dictionary");
}
}
}
@ -428,8 +428,8 @@ QPDFObjectHandle::getPageContents()
}
else
{
throw QEXC::General("unknown object type inspecting /Contents "
"key in page dictionary");
throw std::runtime_error("unknown object type inspecting /Contents "
"key in page dictionary");
}
return result;
@ -542,7 +542,8 @@ QPDFObjectHandle::makeDirectInternal(std::set<int>& visited)
if (isStream())
{
QTC::TC("qpdf", "QPDFObjectHandle ERR clone stream");
throw QEXC::General("attempt to make a stream into a direct object");
throw std::runtime_error(
"attempt to make a stream into a direct object");
}
int cur_objid = this->objid;
@ -551,8 +552,9 @@ QPDFObjectHandle::makeDirectInternal(std::set<int>& visited)
if (visited.count(cur_objid))
{
QTC::TC("qpdf", "QPDFObjectHandle makeDirect loop");
throw QEXC::General("loop detected while converting object from "
"indirect to direct");
throw std::runtime_error(
"loop detected while converting object from "
"indirect to direct");
}
visited.insert(cur_objid);
}
@ -620,8 +622,8 @@ QPDFObjectHandle::makeDirectInternal(std::set<int>& visited)
}
else
{
throw QEXC::Internal("QPDFObjectHandle::makeIndirect: "
"unknown object type");
throw std::logic_error("QPDFObjectHandle::makeIndirect: "
"unknown object type");
}
this->obj = new_obj;
@ -644,8 +646,8 @@ QPDFObjectHandle::assertInitialized() const
{
if (! this->initialized)
{
throw QEXC::Internal("operation attempted on uninitialized "
"QPDFObjectHandle");
throw std::logic_error("operation attempted on uninitialized "
"QPDFObjectHandle");
}
}
@ -654,8 +656,8 @@ QPDFObjectHandle::assertType(char const* type_name, bool istype)
{
if (! istype)
{
throw QEXC::Internal(std::string("operation for ") + type_name +
" object attempted on object of wrong type");
throw std::logic_error(std::string("operation for ") + type_name +
" object attempted on object of wrong type");
}
}
@ -665,7 +667,7 @@ QPDFObjectHandle::assertPageObject()
if (! (this->isDictionary() && this->hasKey("/Type") &&
(this->getKey("/Type").getName() == "/Page")))
{
throw QEXC::Internal("page operation called on non-Page object");
throw std::logic_error("page operation called on non-Page object");
}
}

View File

@ -1,4 +1,3 @@
#include <qpdf/QPDFTokenizer.hh>
// DO NOT USE ctype -- it is locale dependent for some things, and
@ -6,9 +5,9 @@
// be used.
#include <qpdf/PCRE.hh>
#include <qpdf/QEXC.hh>
#include <qpdf/QTC.hh>
#include <stdexcept>
#include <string.h>
// See note above about ctype.
@ -55,8 +54,9 @@ QPDFTokenizer::presentCharacter(char ch)
if (state == st_token_ready)
{
throw QEXC::Internal("QPDF tokenizer presented character "
"while token is waiting");
throw std::logic_error(
"INTERNAL ERROR: QPDF tokenizer presented character "
"while token is waiting");
}
char orig_ch = ch;
@ -237,8 +237,9 @@ QPDFTokenizer::presentCharacter(char ch)
// last_char_was_bs is set/cleared below as appropriate
if (bs_num_count)
{
throw QEXC::Internal("QPDFTokenizer: bs_num_count != 0 "
"when ch == '\\'");
throw std::logic_error(
"INTERNAL ERROR: QPDFTokenizer: bs_num_count != 0 "
"when ch == '\\'");
}
}
else if (ch == '(')
@ -333,7 +334,8 @@ QPDFTokenizer::presentCharacter(char ch)
}
else
{
throw QEXC::Internal("invalid state while reading token");
throw std::logic_error(
"INTERNAL ERROR: invalid state while reading token");
}
if ((state == st_token_ready) && (type == tt_word))

View File

@ -1,4 +1,3 @@
#include <qpdf/QPDFWriter.hh>
#include <assert.h>
@ -479,8 +478,8 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object)
}
else if (object.isScalar())
{
throw QEXC::Internal(
"QPDFWriter::enqueueObject: indirect scalar: " +
throw std::logic_error(
"INTERNAL ERROR: QPDFWriter::enqueueObject: indirect scalar: " +
std::string(this->filename) + " " +
QUtil::int_to_string(object.getObjectID()) + " " +
QUtil::int_to_string(object.getGeneration()));
@ -559,8 +558,8 @@ QPDFWriter::unparseChild(QPDFObjectHandle child, int level, int flags)
{
if (child.isScalar())
{
throw QEXC::Internal(
"QPDFWriter::unparseChild: indirect scalar: " +
throw std::logic_error(
"INTERNAL ERROR: QPDFWriter::unparseChild: indirect scalar: " +
QUtil::int_to_string(child.getObjectID()) + " " +
QUtil::int_to_string(child.getGeneration()));
}
@ -1599,7 +1598,7 @@ QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset,
break;
default:
throw QEXC::Internal("invalid type writing xref stream");
throw std::logic_error("invalid type writing xref stream");
break;
}
}

View File

@ -1,4 +1,3 @@
#include <qpdf/QPDFXRefEntry.hh>
#include <qpdf/QPDFExc.hh>
#include <qpdf/QUtil.hh>

View File

@ -1,7 +1,5 @@
#include <qpdf/QPDF_Array.hh>
#include <qpdf/QEXC.hh>
#include <stdexcept>
QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& items) :
items(items)
@ -37,7 +35,8 @@ QPDF_Array::getItem(int n) const
{
if ((n < 0) || (n >= (int)this->items.size()))
{
throw QEXC::Internal("bounds array accessing QPDF_Array element");
throw std::logic_error(
"INTERNAL ERROR: bounds array accessing QPDF_Array element");
}
return this->items[n];
}

View File

@ -1,4 +1,3 @@
#include <qpdf/QPDF_Bool.hh>
QPDF_Bool::QPDF_Bool(bool val) :

View File

@ -1,4 +1,3 @@
#include <qpdf/QPDF_Dictionary.hh>
#include <qpdf/QPDF_Null.hh>

View File

@ -1,4 +1,3 @@
#include <qpdf/QPDF_Integer.hh>
#include <qpdf/QUtil.hh>

View File

@ -1,4 +1,3 @@
#include <qpdf/QPDF_Name.hh>
#include <string.h>

View File

@ -1,4 +1,3 @@
#include <qpdf/QPDF_Null.hh>
QPDF_Null::~QPDF_Null()

View File

@ -1,4 +1,3 @@
#include <qpdf/QPDF_Real.hh>
QPDF_Real::QPDF_Real(std::string const& val) :

View File

@ -1,7 +1,5 @@
#include <qpdf/QPDF_Stream.hh>
#include <qpdf/QEXC.hh>
#include <qpdf/QUtil.hh>
#include <qpdf/Pipeline.hh>
#include <qpdf/Pl_Flate.hh>
@ -17,6 +15,8 @@
#include <qpdf/QPDFExc.hh>
#include <qpdf/Pl_QPDFTokenizer.hh>
#include <stdexcept>
QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation,
QPDFObjectHandle stream_dict,
off_t offset, int length) :
@ -29,8 +29,9 @@ QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation,
{
if (! stream_dict.isDictionary())
{
throw QEXC::Internal("stream object instantiated with non-dictionary "
"object for dictionary");
throw std::logic_error(
"stream object instantiated with non-dictionary "
"object for dictionary");
}
}
@ -298,8 +299,9 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter,
}
else
{
throw QEXC::Internal("QPDFStream: unknown filter "
"encountered after check");
throw std::logic_error(
"INTERNAL ERROR: QPDFStream: unknown filter "
"encountered after check");
}
}
}

View File

@ -1,4 +1,3 @@
#include <qpdf/QPDF_String.hh>
#include <qpdf/QUtil.hh>

View File

@ -386,7 +386,8 @@ QPDF::getKeyForObject(int objid, int generation)
{
if (! this->encrypted)
{
throw QEXC::Internal("request for encryption key in non-encrypted PDF");
throw std::logic_error(
"request for encryption key in non-encrypted PDF");
}
if (! ((objid == this->cached_key_objid) &&

View File

@ -1177,8 +1177,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
{
// Note that we can't call optimize here because we don't know
// whether it should be called with or without allow changes.
throw QEXC::Internal("QPDF::calculateLinearizationData "
"called before optimize()");
throw std::logic_error(
"INTERNAL ERROR: QPDF::calculateLinearizationData "
"called before optimize()");
}
// Separate objects into the categories sufficient for us to
@ -1336,8 +1337,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
break;
case ObjUser::ou_bad:
throw QEXC::Internal("QPDF::calculateLinearizationData: "
"invalid user type");
throw std::logic_error(
"INTERNAL ERROR: QPDF::calculateLinearizationData: "
"invalid user type");
break;
}
}
@ -1444,8 +1446,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
ObjGen first_page_og(pages[0].getObjectID(), pages[0].getGeneration());
if (! lc_first_page_private.count(first_page_og))
{
throw QEXC::Internal("QPDF::calculateLinearizationData: first page "
"object not in lc_first_page_private");
throw std::logic_error(
"INTERNAL ERROR: QPDF::calculateLinearizationData: first page "
"object not in lc_first_page_private");
}
lc_first_page_private.erase(first_page_og);
this->c_linp.first_page_object = pages[0].getObjectID();
@ -1492,7 +1495,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
ObjGen page_og(pages[i].getObjectID(), pages[i].getGeneration());
if (! lc_other_page_private.count(page_og))
{
throw QEXC::Internal(
throw std::logic_error(
"INTERNAL ERROR: "
"QPDF::calculateLinearizationData: page object for page " +
QUtil::int_to_string(i) + " not in lc_other_page_private");
}
@ -1522,8 +1526,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// That should have covered all part7 objects.
if (! lc_other_page_private.empty())
{
throw QEXC::Internal(
"QPDF::calculateLinearizationData: lc_other_page_private is "
throw std::logic_error(
"INTERNAL ERROR:"
" QPDF::calculateLinearizationData: lc_other_page_private is "
"not empty after generation of part7");
}
@ -1601,7 +1606,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
}
if (! lc_thumbnail_private.empty())
{
throw QEXC::Internal(
throw std::logic_error(
"INTERNAL ERROR: "
"QPDF::calculateLinearizationData: lc_thumbnail_private "
"not empty after placing thumbnails");
}
@ -1633,11 +1639,12 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
unsigned int num_wanted = this->object_to_obj_users.size();
if (num_placed != num_wanted)
{
throw QEXC::Internal("QPDF::calculateLinearizationData: wrong "
"number of objects placed (num_placed = " +
QUtil::int_to_string(num_placed) +
"; number of objects: " +
QUtil::int_to_string(num_wanted));
throw std::logic_error(
"INTERNAL ERROR: QPDF::calculateLinearizationData: wrong "
"number of objects placed (num_placed = " +
QUtil::int_to_string(num_placed) +
"; number of objects: " +
QUtil::int_to_string(num_wanted));
}
// Calculate shared object hint table information including

View File

@ -78,8 +78,9 @@ QPDF::flattenScalarReferences()
{
if (node.isScalar())
{
throw QEXC::Internal(
"flattenScalarReferences landed at indirect scalar");
throw std::logic_error(
"INTERNAL ERROR:"
" flattenScalarReferences landed at indirect scalar");
}
ObjGen og(node.getObjectID(), node.getGeneration());
if (visited.count(og) > 0)
@ -124,7 +125,8 @@ QPDF::flattenScalarReferences()
{
// QPDF_Dictionary.getKeys() never returns null
// keys.
throw QEXC::Internal("dictionary with null key found");
throw std::logic_error(
"INTERNAL ERROR: dictionary with null key found");
}
else if (oh.isScalar())
{

View File

@ -1,4 +1,3 @@
#include <qpdf/QTC.hh>
#include <set>

View File

@ -1,4 +1,4 @@
#include <qpdf/DLL.hh>
#include <qpdf/QUtil.hh>
#include <stdio.h>
#include <errno.h>
@ -25,9 +25,9 @@ QUtil::int_to_string(int num, int fullpad)
// -2 or -1 to leave space for the possible negative sign and for NUL...
if (abs(fullpad) > (int)sizeof(t) - ((num < 0)?2:1))
{
throw QEXC::Internal("Util::int_to_string has been called with "
"a padding value greater than its internal "
"limit");
throw std::logic_error("Util::int_to_string has been called with "
"a padding value greater than its internal "
"limit");
}
if (fullpad)
@ -62,9 +62,9 @@ QUtil::double_to_string(double num, int decimal_places)
// always pass in those cases.
if (decimal_places + 1 + (int)lhs.length() > (int)sizeof(t) - 1)
{
throw QEXC::Internal("Util::double_to_string has been called with "
"a number and a decimal places specification "
"that would break an internal limit");
throw std::logic_error("Util::double_to_string has been called with "
"a number and a decimal places specification "
"that would break an internal limit");
}
if (decimal_places)
@ -78,24 +78,31 @@ QUtil::double_to_string(double num, int decimal_places)
return std::string(t);
}
DLL_EXPORT
void
QUtil::throw_system_error(std::string const& description)
{
throw std::runtime_error(description + ": " + strerror(errno));
}
DLL_EXPORT
int
QUtil::os_wrapper(std::string const& description, int status) throw (QEXC::System)
QUtil::os_wrapper(std::string const& description, int status)
{
if (status == -1)
{
throw QEXC::System(description, errno);
throw_system_error(description);
}
return status;
}
DLL_EXPORT
FILE*
QUtil::fopen_wrapper(std::string const& description, FILE* f) throw (QEXC::System)
QUtil::fopen_wrapper(std::string const& description, FILE* f)
{
if (f == 0)
{
throw QEXC::System(description, errno);
throw_system_error(description);
}
return f;
}
@ -240,7 +247,7 @@ QUtil::toUTF8(unsigned long uval)
if (uval > 0x7fffffff)
{
throw QEXC::General("bounds error in QUtil::toUTF8");
throw std::runtime_error("bounds error in QUtil::toUTF8");
}
else if (uval < 128)
{
@ -267,7 +274,7 @@ QUtil::toUTF8(unsigned long uval)
--cur_byte;
if (cur_byte < bytes)
{
throw QEXC::Internal("QUtil::toUTF8: overflow error");
throw std::logic_error("QUtil::toUTF8: overflow error");
}
}
// If maxval is k bits long, the high (7 - k) bits of the

View File

@ -1,4 +1,3 @@
#include <qpdf/RC4.hh>
#include <string.h>

View File

@ -3,8 +3,8 @@
#define __BITS_CC__
#include <algorithm>
#include <stdexcept>
#include <qpdf/QTC.hh>
#include <qpdf/QEXC.hh>
#include <qpdf/Pipeline.hh>
// 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,
if (bits_wanted > bits_available)
{
throw QEXC::General("overflow reading bit stream");
throw std::length_error("overflow reading bit stream");
}
if (bits_wanted > 32)
{
throw QEXC::Internal("read_bits: too many bits requested");
throw std::out_of_range("read_bits: too many bits requested");
}
unsigned long result = 0;
@ -99,7 +99,7 @@ write_bits(unsigned char& ch, unsigned int& bit_offset,
{
if (bits > 32)
{
throw QEXC::Internal("write_bits: too many bits requested");
throw std::out_of_range("write_bits: too many bits requested");
}
// bit_offset + 1 is the number of bits left in ch

View File

@ -22,7 +22,6 @@ SRCS_libqpdf = \
libqpdf/Pl_QPDFTokenizer.cc \
libqpdf/Pl_RC4.cc \
libqpdf/Pl_StdioFile.cc \
libqpdf/QEXC.cc \
libqpdf/QPDF.cc \
libqpdf/QPDFExc.cc \
libqpdf/QPDFObject.cc \
@ -69,5 +68,5 @@ $(OBJS_libqpdf): libqpdf/$(OUTPUT_DIR)/%.lo: libqpdf/%.cc
# * Otherwise, increment REVISION
libqpdf/$(OUTPUT_DIR)/libqpdf.la: $(OBJS_libqpdf)
$(call makelib,$(OBJS_libqpdf),$@,2,1,1)
$(call makelib,$(OBJS_libqpdf),$@,3,0,0)

View File

@ -1,10 +1,8 @@
#ifndef __MD5_HH__
#define __MD5_HH__
#include <string>
#include <qpdf/DLL.hh>
#include <qpdf/QEXC.hh>
#include <qpdf/qpdf-config.h>
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
@ -26,8 +24,7 @@ class MD5
// encodes file and finalizes
DLL_EXPORT
void encodeFile(char const* filename, int up_to_size = -1)
throw(QEXC::System);
void encodeFile(char const* filename, int up_to_size = -1);
// appends string to current md5 object
DLL_EXPORT

View File

@ -10,9 +10,9 @@
#endif
#include <pcre.h>
#include <string>
#include <stdexcept>
#include <qpdf/DLL.hh>
#include <qpdf/QEXC.hh>
// Note: this class does not encapsulate all features of the PCRE
// package -- only those that I actually need right now are here.
@ -20,18 +20,9 @@
class PCRE
{
public:
class Exception: public QEXC::General
{
public:
DLL_EXPORT
Exception(std::string const& message);
DLL_EXPORT
virtual ~Exception() throw() {}
};
// This is thrown when an attempt is made to access a non-existent
// back reference.
class NoBackref: public Exception
class NoBackref: public std::logic_error
{
public:
DLL_EXPORT
@ -65,14 +56,13 @@ class PCRE
// see getMatch flags below
DLL_EXPORT
std::string getMatch(int n, int flags = 0)
throw(QEXC::General, Exception);
std::string getMatch(int n, int flags = 0);
DLL_EXPORT
void getOffsetLength(int n, int& offset, int& length) throw(Exception);
void getOffsetLength(int n, int& offset, int& length);
DLL_EXPORT
int getOffset(int n) throw(Exception);
int getOffset(int n);
DLL_EXPORT
int getLength(int n) throw(Exception);
int getLength(int n);
// nMatches returns the number of available matches including
// match 0 which is the whole string. In other words, if you
@ -105,14 +95,13 @@ class PCRE
// The value passed in as options is passed to pcre_exec. See man
// pcreapi for details.
DLL_EXPORT
PCRE(char const* pattern, int options = 0) throw(Exception);
PCRE(char const* pattern, int options = 0);
DLL_EXPORT
~PCRE();
DLL_EXPORT
Match match(char const* subject, int options = 0, int startoffset = 0,
int size = -1)
throw(QEXC::General, Exception);
int size = -1);
DLL_EXPORT
static void test(int n = 0);

View File

@ -1,4 +1,3 @@
#ifndef __PL_ASCII85DECODER_HH__
#define __PL_ASCII85DECODER_HH__

View File

@ -1,4 +1,3 @@
#ifndef __PL_ASCIIHEXDECODER_HH__
#define __PL_ASCIIHEXDECODER_HH__

View File

@ -1,4 +1,3 @@
#ifndef __PL_LZWDECODER_HH__
#define __PL_LZWDECODER_HH__

View File

@ -1,4 +1,3 @@
#ifndef __PL_MD5_HH__
#define __PL_MD5_HH__

View File

@ -19,21 +19,6 @@
class Pl_PNGFilter: public Pipeline
{
public:
class Exception: public Pipeline::Exception
{
public:
DLL_EXPORT
Exception(std::string const& message) :
Pipeline::Exception(message)
{
}
DLL_EXPORT
virtual ~Exception() throw ()
{
}
};
// Encoding is not presently supported
enum action_e { a_encode, a_decode };

View File

@ -1,4 +1,3 @@
#ifndef __PL_QPDFTOKENIZER_HH__
#define __PL_QPDFTOKENIZER_HH__

View File

@ -1,4 +1,3 @@
#ifndef __PL_RC4_HH__
#define __PL_RC4_HH__
@ -9,21 +8,6 @@
class Pl_RC4: public Pipeline
{
public:
class Exception: public Pipeline::Exception
{
public:
DLL_EXPORT
Exception(std::string const& message) :
Pipeline::Exception(message)
{
}
DLL_EXPORT
virtual ~Exception() throw()
{
}
};
static int const def_bufsize = 65536;
// key_len of -1 means treat key_data as a null-terminated string

View File

@ -1,4 +1,3 @@
#ifndef __QPDF_ARRAY_HH__
#define __QPDF_ARRAY_HH__

View File

@ -1,4 +1,3 @@
#ifndef __QPDF_BOOL_HH__
#define __QPDF_BOOL_HH__

View File

@ -1,4 +1,3 @@
#ifndef __QPDF_DICTIONARY_HH__
#define __QPDF_DICTIONARY_HH__

View File

@ -1,4 +1,3 @@
#ifndef __QPDF_INTEGER_HH__
#define __QPDF_INTEGER_HH__

View File

@ -1,4 +1,3 @@
#ifndef __QPDF_NAME_HH__
#define __QPDF_NAME_HH__

View File

@ -1,4 +1,3 @@
#ifndef __QPDF_NULL_HH__
#define __QPDF_NULL_HH__

View File

@ -1,4 +1,3 @@
#ifndef __QPDF_REAL_HH__
#define __QPDF_REAL_HH__

View File

@ -1,4 +1,3 @@
#ifndef __QPDF_STREAM_HH__
#define __QPDF_STREAM_HH__

View File

@ -1,4 +1,3 @@
#ifndef __QPDF_STRING_HH__
#define __QPDF_STRING_HH__

View File

@ -1,4 +1,3 @@
#ifndef __RC4_HH__
#define __RC4_HH__

View File

@ -1,4 +1,3 @@
#include <qpdf/BitStream.hh>
#include <qpdf/BitWriter.hh>
#include <qpdf/Pl_Buffer.hh>

View File

@ -1,4 +1,3 @@
#include <qpdf/Pl_Buffer.hh>
#include <qpdf/Pl_Count.hh>
#include <qpdf/Pl_Discard.hh>

View File

@ -9,7 +9,6 @@ BINS_libtests = \
pcre \
png_filter \
pointer_holder \
qexc \
qutil \
rc4

View File

@ -105,9 +105,9 @@ int main(int argc, char* argv[])
{
run(filename);
}
catch (QEXC::General& e)
catch (std::exception& e)
{
std::cout << e.unparse() << std::endl;
std::cout << e.what() << std::endl;
}
return 0;
}

View File

@ -1,4 +1,3 @@
#include <qpdf/MD5.hh>
#include <qpdf/Pl_MD5.hh>
#include <qpdf/Pl_Discard.hh>

View File

@ -1,4 +1,3 @@
#include <qpdf/PCRE.hh>
#include <iostream>
#include <string.h>
@ -12,7 +11,7 @@ int main(int argc, char* argv[])
PCRE("^([\\p{L}]+)", PCRE_UTF8);
std::cout << "1" << std::endl;
}
catch (PCRE::Exception& e)
catch (std::exception& e)
{
std::cout << "0" << std::endl;
}

View File

@ -1,4 +1,3 @@
#include <qpdf/Pl_PNGFilter.hh>
#include <qpdf/Pl_StdioFile.hh>
@ -79,9 +78,9 @@ int main(int argc, char* argv[])
{
run(filename, encode, columns);
}
catch (QEXC::General& e)
catch (std::exception& e)
{
std::cout << e.unparse() << std::endl;
std::cout << e.what() << std::endl;
}
return 0;
}

View File

@ -1,4 +1,3 @@
#include <qpdf/PointerHolder.hh>
#include <iostream>

View File

@ -1,53 +0,0 @@
#include <qpdf/QEXC.hh>
#include <iostream>
#include <errno.h>
#include <stdlib.h>
void f(int n)
{
switch (n)
{
case 0:
throw QEXC::General("general exception");
break;
case 1:
throw QEXC::Internal("internal error");
break;
case 2:
throw QEXC::System("doing something", EINVAL);
break;
}
}
int main(int argc, char* argv[])
{
if (argc != 2)
{
std::cerr << "usage: qexc n" << std::endl;
exit(2);
}
try
{
f(atoi(argv[1]));
}
catch (QEXC::General& e)
{
std::cerr << "exception: " << e.unparse() << std::endl;
std::cerr << "what: " << e.what() << std::endl;
exit(2);
}
catch (std::exception& e)
{
std::cerr << "uncaught exception: " << e.what() << std::endl;
exit(3);
}
catch (...)
{
exit(4);
}
return 0;
}

View File

@ -5,7 +5,7 @@ data: 1234567890abcdefghij
count: 32
size: 11
data: qwertyuiop
INTERNAL ERROR: Pl_Buffer::getBuffer() called when not ready
Pl_Buffer::getBuffer() called when not ready
size: 9
data: mooquack
done

View File

@ -1,28 +0,0 @@
#!/usr/bin/env perl
require 5.008;
BEGIN { $^W = 1; }
use strict;
chdir("qexc") or die "chdir qexc failed: $!\n";
require TestDriver;
my $td = new TestDriver('qexc');
my @tests =
(['general exception', 2],
['internal error', 3],
['system exception', 2],
);
for (my $i = 0; $i < scalar(@tests); ++$i)
{
$td->runtest($tests[$i]->[0],
{$td->COMMAND => "qexc $i"},
{$td->FILE => "test$i.out",
$td->EXIT_STATUS => $tests[$i]->[1]},
$td->NORMALIZE_NEWLINES);
}
$td->report(scalar(@tests));

View File

@ -1,2 +0,0 @@
exception: general exception
what: general exception

View File

@ -1 +0,0 @@
uncaught exception: INTERNAL ERROR: internal error

View File

@ -1,2 +0,0 @@
exception: doing something: Invalid argument
what: doing something: Invalid argument

View File

@ -4,11 +4,11 @@
3.141590
3.142
1000.123000
exception 1: INTERNAL ERROR: Util::int_to_string has been called with a padding value greater than its internal limit
exception 2: INTERNAL ERROR: Util::int_to_string has been called with a padding value greater than its internal limit
exception 3: INTERNAL ERROR: Util::int_to_string has been called with a padding value greater than its internal limit
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
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
exception 1: Util::int_to_string has been called with a padding value greater than its internal limit
exception 2: Util::int_to_string has been called with a padding value greater than its internal limit
exception 3: Util::int_to_string has been called with a padding value greater than its internal limit
exception 4: Util::double_to_string has been called with a number and a decimal places specification that would break an internal limit
exception 5: Util::double_to_string has been called with a number and a decimal places specification that would break an internal limit
one
7
compare okay

View File

@ -1,4 +1,3 @@
#include <iostream>
#include <stdio.h>
#include <sys/types.h>
@ -27,9 +26,9 @@ void string_conversion_test()
// int_to_string bounds error
std::cout << QUtil::int_to_string(1, 50) << std::endl;
}
catch(QEXC::Internal &e)
catch (std::logic_error &e)
{
std::cout << "exception 1: " << e.unparse() << std::endl;
std::cout << "exception 1: " << e.what() << std::endl;
}
try
@ -37,9 +36,9 @@ void string_conversion_test()
// QUtil::int_to_string bounds error
std::cout << QUtil::int_to_string(1, -50) << std::endl;
}
catch(QEXC::Internal &e)
catch (std::logic_error& e)
{
std::cout << "exception 2: " << e.unparse() << std::endl;
std::cout << "exception 2: " << e.what() << std::endl;
}
try
@ -47,9 +46,9 @@ void string_conversion_test()
// QUtil::int_to_string bounds error
std::cout << QUtil::int_to_string(-1, 49) << std::endl;
}
catch(QEXC::Internal &e)
catch (std::logic_error& e)
{
std::cout << "exception 3: " << e.unparse() << std::endl;
std::cout << "exception 3: " << e.what() << std::endl;
}
@ -58,9 +57,9 @@ void string_conversion_test()
// QUtil::double_to_string bounds error
std::cout << QUtil::double_to_string(3.14159, 1024) << std::endl;
}
catch(QEXC::Internal &e)
catch (std::logic_error& e)
{
std::cout << "exception 4: " << e.unparse() << std::endl;
std::cout << "exception 4: " << e.what() << std::endl;
}
try
@ -68,9 +67,9 @@ void string_conversion_test()
// QUtil::double_to_string bounds error
std::cout << QUtil::double_to_string(1000.0, 95) << std::endl;
}
catch(QEXC::Internal &e)
catch (std::logic_error& e)
{
std::cout << "exception 5: " << e.unparse() << std::endl;
std::cout << "exception 5: " << e.what() << std::endl;
}
std::string embedded_null = "one";
@ -101,9 +100,9 @@ void os_wrapper_test()
std::cout << "after open" << std::endl;
(void) close(fd);
}
catch (QEXC::System& s)
catch (std::runtime_error& s)
{
std::cout << "exception: " << s.unparse() << std::endl;
std::cout << "exception: " << s.what() << std::endl;
}
}
@ -118,9 +117,9 @@ void fopen_wrapper_test()
std::cout << "after fopen" << std::endl;
(void) fclose(f);
}
catch (QEXC::System& s)
catch (std::runtime_error& s)
{
std::cout << "exception: " << s.unparse() << std::endl;
std::cout << "exception: " << s.what() << std::endl;
}
}
@ -171,7 +170,7 @@ void to_utf8_test()
{
print_utf8(0x80000000UL);
}
catch (QEXC::General& e)
catch (std::runtime_error& e)
{
std::cout << "0x80000000: " << e.what() << std::endl;
}

View File

@ -1,4 +1,3 @@
#include <qpdf/Pl_RC4.hh>
#include <qpdf/Pl_StdioFile.hh>

View File

@ -1,4 +1,3 @@
#include <iostream>
#include <string.h>
#include <stdlib.h>
@ -943,7 +942,7 @@ int main(int argc, char* argv[])
}
else
{
throw QEXC::Internal("bad encryption keylen");
throw std::logic_error("bad encryption keylen");
}
}
if (linearize)

View File

@ -284,8 +284,8 @@ void runtest(int n, char const* filename)
}
else
{
throw QEXC::General(std::string("invalid test ") +
QUtil::int_to_string(n));
throw std::runtime_error(std::string("invalid test ") +
QUtil::int_to_string(n));
}
std::cout << "test " << n << " done" << std::endl;