diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-01-25 22:40:35 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-01-30 19:11:03 +0100 |
commit | 9373881cca0c781c66b2b50b962bdbc26364abe5 (patch) | |
tree | 50839b0d13d3178a3d7bd795de8fce39806e840e | |
parent | 0a354af02cf51aeb1602596988c8f826b47b3a81 (diff) | |
download | qpdf-9373881cca0c781c66b2b50b962bdbc26364abe5.tar.zst |
Add QPDFJob::ConfigError exception
-rw-r--r-- | include/qpdf/QPDFJob.hh | 10 | ||||
-rw-r--r-- | libqpdf/QPDFJob.cc | 5 | ||||
-rw-r--r-- | libqpdf/QPDFJob_config.cc | 20 | ||||
-rw-r--r-- | qpdf/qpdf.cc | 4 |
4 files changed, 26 insertions, 13 deletions
diff --git a/include/qpdf/QPDFJob.hh b/include/qpdf/QPDFJob.hh index 734f5f45..853f7969 100644 --- a/include/qpdf/QPDFJob.hh +++ b/include/qpdf/QPDFJob.hh @@ -36,12 +36,22 @@ #include <iostream> #include <functional> #include <memory> +#include <stdexcept> class QPDFWriter; class QPDFJob { public: + // ConfigError exception is thrown if there are any usage-like + // errors when calling Config methods. + class QPDF_DLL_CLASS ConfigError: public std::runtime_error + { + public: + QPDF_DLL + ConfigError(std::string const&); + }; + QPDF_DLL QPDFJob(); diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index ca479812..eb06e076 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -33,6 +33,11 @@ #include <qpdf/QPDFWriter.hh> #include <qpdf/QIntC.hh> +QPDFJob::ConfigError::ConfigError(std::string const& msg) : + std::runtime_error(msg) +{ +} + namespace { class ImageOptimizer: public QPDFObjectHandle::StreamDataProvider diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc index ad970aa4..7342aeea 100644 --- a/libqpdf/QPDFJob_config.cc +++ b/libqpdf/QPDFJob_config.cc @@ -534,9 +534,7 @@ QPDFJob::CopyAttConfig::end() { if (this->caf.path.empty()) { - // QXXXQ usage, json, and config exceptions need to be unified - // in some fashion. - throw std::runtime_error("copy attachments: no path specified"); + throw QPDFJob::ConfigError("copy attachments: no path specified"); } this->config.o.attachments_to_copy.push_back(this->caf); return this->config; @@ -579,8 +577,7 @@ QPDFJob::AttConfig::creationdate(char const* parameter) { if (! QUtil::pdf_time_to_qpdf_time(parameter)) { - // QXXXQ - throw std::runtime_error( + throw QPDFJob::ConfigError( std::string(parameter) + " is not a valid PDF timestamp"); } this->att.creationdate = parameter; @@ -592,8 +589,7 @@ QPDFJob::AttConfig::moddate(char const* parameter) { if (! QUtil::pdf_time_to_qpdf_time(parameter)) { - // QXXXQ - throw std::runtime_error( + throw QPDFJob::ConfigError( std::string(parameter) + " is not a valid PDF timestamp"); } this->att.moddate = parameter; @@ -605,8 +601,7 @@ QPDFJob::AttConfig::mimetype(char const* parameter) { if (strchr(parameter, '/') == nullptr) { - // QXXXQ - throw std::runtime_error( + throw QPDFJob::ConfigError( "mime type should be specified as type/subtype"); } this->att.mimetype = parameter; @@ -630,18 +625,17 @@ QPDFJob::AttConfig::replace() QPDFJob::Config& QPDFJob::AttConfig::end() { - // QXXXQ runtime_error - static std::string now = QUtil::qpdf_time_to_pdf_time( QUtil::get_current_qpdf_time()); if (this->att.path.empty()) { - throw std::runtime_error("add attachment: no path specified"); + throw QPDFJob::ConfigError("add attachment: no path specified"); } std::string last_element = QUtil::path_basename(this->att.path); if (last_element.empty()) { - throw std::runtime_error("path for --add-attachment may not be empty"); + throw QPDFJob::ConfigError( + "path for --add-attachment may not be empty"); } if (this->att.filename.empty()) { diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index 04cd2244..0e7eaf65 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -52,6 +52,10 @@ int realmain(int argc, char* argv[]) { usageExit(e.what()); } + catch (QPDFJob::ConfigError& e) + { + usageExit(e.what()); + } catch (std::exception& e) { std::cerr << whoami << ": " << e.what() << std::endl; |