Coverage Report

Created: 2025-11-11 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qpdf/include/qpdf/QPDFExc.hh
Line
Count
Source
1
// Copyright (c) 2005-2021 Jay Berkenbilt
2
// Copyright (c) 2022-2025 Jay Berkenbilt and Manfred Holger
3
//
4
// This file is part of qpdf.
5
//
6
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7
// in compliance with the License. You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software distributed under the License
12
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13
// or implied. See the License for the specific language governing permissions and limitations under
14
// the License.
15
//
16
// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic
17
// License. At your option, you may continue to consider qpdf to be licensed under those terms.
18
// Please see the manual for additional information.
19
20
#ifndef QPDFEXC_HH
21
#define QPDFEXC_HH
22
23
#include <qpdf/Constants.h>
24
#include <qpdf/DLL.h>
25
#include <qpdf/Types.h>
26
27
#include <stdexcept>
28
#include <string>
29
30
class QPDF_DLL_CLASS QPDFExc: public std::runtime_error
31
{
32
  public:
33
    QPDF_DLL
34
    QPDFExc(
35
        qpdf_error_code_e error_code,
36
        std::string const& filename,
37
        std::string const& object,
38
        qpdf_offset_t offset,
39
        std::string const& message);
40
41
    QPDF_DLL
42
    QPDFExc(
43
        qpdf_error_code_e error_code,
44
        std::string const& filename,
45
        std::string const& object,
46
        qpdf_offset_t offset,
47
        std::string const& message,
48
        bool zero_offset_valid);
49
50
2.01M
    ~QPDFExc() noexcept override = default;
51
52
    // To get a complete error string, call what(), provided by std::exception.  The accessors below
53
    // return the original values used to create the exception.  Only the error code and message are
54
    // guaranteed to have non-zero/empty values.
55
56
    // There is no lookup code that maps numeric error codes into strings.  The numeric error code
57
    // is just another way to get at the underlying issue, but it is more programmer-friendly than
58
    // trying to parse a string that is subject to change.
59
60
    QPDF_DLL
61
    qpdf_error_code_e getErrorCode() const;
62
    QPDF_DLL
63
    std::string const& getFilename() const;
64
    QPDF_DLL
65
    std::string const& getObject() const;
66
    QPDF_DLL
67
    qpdf_offset_t getFilePosition() const;
68
    QPDF_DLL
69
    std::string const& getMessageDetail() const;
70
71
  private:
72
    QPDF_DLL_PRIVATE
73
    static std::string createWhat(
74
        std::string const& filename,
75
        std::string const& object,
76
        qpdf_offset_t offset,
77
        std::string const& message);
78
79
    // This class does not use the Members pattern to avoid needless memory allocations during
80
    // exception handling.
81
82
    qpdf_error_code_e error_code;
83
    std::string filename;
84
    std::string object;
85
    qpdf_offset_t offset;
86
    std::string message;
87
};
88
89
#endif // QPDFEXC_HH