diff options
Diffstat (limited to 'libqpdf/QPDFExc.cc')
-rw-r--r-- | libqpdf/QPDFExc.cc | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/libqpdf/QPDFExc.cc b/libqpdf/QPDFExc.cc index 006a96ac..614990a9 100644 --- a/libqpdf/QPDFExc.cc +++ b/libqpdf/QPDFExc.cc @@ -1,18 +1,56 @@ #include <qpdf/QPDFExc.hh> #include <qpdf/QUtil.hh> -QPDFExc::QPDFExc(std::string const& message) : - std::runtime_error(message) +QPDFExc::QPDFExc(qpdf_error_code_e error_code, + std::string const& filename, + std::string const& object, + off_t offset, + std::string const& message) : + std::runtime_error(createWhat(filename, object, offset, message)), + error_code(error_code), + filename(filename), + object(object), + offset(offset), + message(message) { } -QPDFExc::QPDFExc(std::string const& filename, int offset, - std::string const& message) : - std::runtime_error(filename + ": offset " + QUtil::int_to_string(offset) + - ": " + message) +QPDFExc::~QPDFExc() throw () { } -QPDFExc::~QPDFExc() throw () +std::string +QPDFExc::createWhat(std::string const& filename, + std::string const& object, + off_t offset, + std::string const& message) { + std::string result; + if (! filename.empty()) + { + result += filename; + } + if (! (object.empty() && offset == 0)) + { + result += " ("; + if (! object.empty()) + { + result += object; + if (offset > 0) + { + result += ", "; + } + } + if (offset > 0) + { + result += "file position " + QUtil::int_to_string(offset); + } + result += ")"; + } + if (! result.empty()) + { + result += ": "; + } + result += message; + return result; } |