Commit 9373881cca0c781c66b2b50b962bdbc26364abe5
1 parent
0a354af0
Add QPDFJob::ConfigError exception
Showing
4 changed files
with
26 additions
and
13 deletions
include/qpdf/QPDFJob.hh
| ... | ... | @@ -36,12 +36,22 @@ |
| 36 | 36 | #include <iostream> |
| 37 | 37 | #include <functional> |
| 38 | 38 | #include <memory> |
| 39 | +#include <stdexcept> | |
| 39 | 40 | |
| 40 | 41 | class QPDFWriter; |
| 41 | 42 | |
| 42 | 43 | class QPDFJob |
| 43 | 44 | { |
| 44 | 45 | public: |
| 46 | + // ConfigError exception is thrown if there are any usage-like | |
| 47 | + // errors when calling Config methods. | |
| 48 | + class QPDF_DLL_CLASS ConfigError: public std::runtime_error | |
| 49 | + { | |
| 50 | + public: | |
| 51 | + QPDF_DLL | |
| 52 | + ConfigError(std::string const&); | |
| 53 | + }; | |
| 54 | + | |
| 45 | 55 | QPDF_DLL |
| 46 | 56 | QPDFJob(); |
| 47 | 57 | ... | ... |
libqpdf/QPDFJob.cc
| ... | ... | @@ -33,6 +33,11 @@ |
| 33 | 33 | #include <qpdf/QPDFWriter.hh> |
| 34 | 34 | #include <qpdf/QIntC.hh> |
| 35 | 35 | |
| 36 | +QPDFJob::ConfigError::ConfigError(std::string const& msg) : | |
| 37 | + std::runtime_error(msg) | |
| 38 | +{ | |
| 39 | +} | |
| 40 | + | |
| 36 | 41 | namespace |
| 37 | 42 | { |
| 38 | 43 | class ImageOptimizer: public QPDFObjectHandle::StreamDataProvider | ... | ... |
libqpdf/QPDFJob_config.cc
| ... | ... | @@ -534,9 +534,7 @@ QPDFJob::CopyAttConfig::end() |
| 534 | 534 | { |
| 535 | 535 | if (this->caf.path.empty()) |
| 536 | 536 | { |
| 537 | - // QXXXQ usage, json, and config exceptions need to be unified | |
| 538 | - // in some fashion. | |
| 539 | - throw std::runtime_error("copy attachments: no path specified"); | |
| 537 | + throw QPDFJob::ConfigError("copy attachments: no path specified"); | |
| 540 | 538 | } |
| 541 | 539 | this->config.o.attachments_to_copy.push_back(this->caf); |
| 542 | 540 | return this->config; |
| ... | ... | @@ -579,8 +577,7 @@ QPDFJob::AttConfig::creationdate(char const* parameter) |
| 579 | 577 | { |
| 580 | 578 | if (! QUtil::pdf_time_to_qpdf_time(parameter)) |
| 581 | 579 | { |
| 582 | - // QXXXQ | |
| 583 | - throw std::runtime_error( | |
| 580 | + throw QPDFJob::ConfigError( | |
| 584 | 581 | std::string(parameter) + " is not a valid PDF timestamp"); |
| 585 | 582 | } |
| 586 | 583 | this->att.creationdate = parameter; |
| ... | ... | @@ -592,8 +589,7 @@ QPDFJob::AttConfig::moddate(char const* parameter) |
| 592 | 589 | { |
| 593 | 590 | if (! QUtil::pdf_time_to_qpdf_time(parameter)) |
| 594 | 591 | { |
| 595 | - // QXXXQ | |
| 596 | - throw std::runtime_error( | |
| 592 | + throw QPDFJob::ConfigError( | |
| 597 | 593 | std::string(parameter) + " is not a valid PDF timestamp"); |
| 598 | 594 | } |
| 599 | 595 | this->att.moddate = parameter; |
| ... | ... | @@ -605,8 +601,7 @@ QPDFJob::AttConfig::mimetype(char const* parameter) |
| 605 | 601 | { |
| 606 | 602 | if (strchr(parameter, '/') == nullptr) |
| 607 | 603 | { |
| 608 | - // QXXXQ | |
| 609 | - throw std::runtime_error( | |
| 604 | + throw QPDFJob::ConfigError( | |
| 610 | 605 | "mime type should be specified as type/subtype"); |
| 611 | 606 | } |
| 612 | 607 | this->att.mimetype = parameter; |
| ... | ... | @@ -630,18 +625,17 @@ QPDFJob::AttConfig::replace() |
| 630 | 625 | QPDFJob::Config& |
| 631 | 626 | QPDFJob::AttConfig::end() |
| 632 | 627 | { |
| 633 | - // QXXXQ runtime_error | |
| 634 | - | |
| 635 | 628 | static std::string now = QUtil::qpdf_time_to_pdf_time( |
| 636 | 629 | QUtil::get_current_qpdf_time()); |
| 637 | 630 | if (this->att.path.empty()) |
| 638 | 631 | { |
| 639 | - throw std::runtime_error("add attachment: no path specified"); | |
| 632 | + throw QPDFJob::ConfigError("add attachment: no path specified"); | |
| 640 | 633 | } |
| 641 | 634 | std::string last_element = QUtil::path_basename(this->att.path); |
| 642 | 635 | if (last_element.empty()) |
| 643 | 636 | { |
| 644 | - throw std::runtime_error("path for --add-attachment may not be empty"); | |
| 637 | + throw QPDFJob::ConfigError( | |
| 638 | + "path for --add-attachment may not be empty"); | |
| 645 | 639 | } |
| 646 | 640 | if (this->att.filename.empty()) |
| 647 | 641 | { | ... | ... |
qpdf/qpdf.cc