PoDoFo  1.0.0-dev
PdfError.h
Go to the documentation of this file.
1 
7 #ifndef PDF_ERROR_H
8 #define PDF_ERROR_H
9 
11 
16 namespace PoDoFo {
17 
25 enum class PdfErrorCode
26 {
27  Unknown = 0,
29  FileNotFound,
30  IOError,
32  OutOfMemory,
38  BrokenFile,
39 
40  InvalidPDF,
47  InvalidXRef,
52  InvalidKey,
53  InvalidName,
58 
62 
63  FlateError,
65 
69 
71 
74 
76  OpenSSLError,
77 };
78 
79 class PODOFO_API PdfErrorInfo final
80 {
81 public:
82  PdfErrorInfo(std::string filepath, unsigned line, std::string info);
83  PdfErrorInfo(const PdfErrorInfo& rhs) = default;
84  PdfErrorInfo& operator=(const PdfErrorInfo& rhs) = default;
85 
86 public:
90  std::string_view GetFilePath() const;
91  const std::string& GetFullFilePath() const { return m_FilePath; }
92  inline unsigned GetLine() const { return m_Line; }
93  inline const std::string& GetInformation() const { return m_Info; }
94 
95 private:
96  unsigned m_Line;
97  std::string m_FilePath;
98  std::string m_Info;
99 };
100 
101 using PdErrorInfoStack = std::deque<PdfErrorInfo>;
102 
103 // This is required to generate the documentation with Doxygen.
104 // Without this define doxygen thinks we have a class called PODOFO_EXCEPTION_API(PODOFO_API) ...
105 #define PODOFO_EXCEPTION_API_DOXYGEN PODOFO_EXCEPTION_API(PODOFO_API)
106 
117 class PODOFO_EXCEPTION_API_DOXYGEN PdfError final : public std::exception
118 {
119  PODOFO_PRIVATE_FRIEND(void AddToCallStack(PdfError& err, std::string filepath, unsigned line, std::string information));
120 
121 public:
130  PdfError(PdfErrorCode code, std::string filepath, unsigned line,
131  std::string information = { });
132 
136  PdfError(const PdfError& rhs) = default;
137 
142  PdfError& operator=(const PdfError& rhs) = default;
143 
149  bool operator==(PdfErrorCode code);
150 
156  bool operator!=(PdfErrorCode code);
157 
158  std::string_view GetName() const;
159 
163  inline PdfErrorCode GetCode() const { return m_Code; }
164 
168  inline const PdErrorInfoStack& GetCallStack() const { return m_CallStack; }
169 
173  void PrintErrorMsg() const;
174 
178  const char* what() const noexcept override;
179 
180 public:
185  static std::string_view ErrorName(PdfErrorCode code);
186 
192  static std::string_view ErrorMessage(PdfErrorCode code);
193 
194 private:
208  void AddToCallStack(std::string&& filepath, unsigned line, std::string&& information);
209 
210  void initFullDescription();
211 
212 private:
213  PdfErrorCode m_Code;
214  PdErrorInfoStack m_CallStack;
215  std::string m_FullDescription;
216 };
217 
218 };
219 
220 #endif // PDF_ERROR_H
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
The error handling class of the PoDoFo library.
Definition: PdfError.h:118
const PdErrorInfoStack & GetCallStack() const
Get access to the internal callstack of this error.
Definition: PdfError.h:168
PdfError & operator=(const PdfError &rhs)=default
Assignment operator.
PdfErrorCode GetCode() const
Return the error code of this object.
Definition: PdfError.h:163
PdfError(const PdfError &rhs)=default
Copy constructor.
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition: basetypes.h:16
PdfErrorCode
Error Code enum values which are used in PdfError to describe the error.
Definition: PdfError.h:26
@ InvalidKey
The specified key is invalid.
@ InvalidXRef
The XRef table is invalid.
@ BrokenFile
The file content is broken.
@ InvalidXRefStream
A XRef stream is invalid.
@ InvalidEnumValue
An invalid enum value was specified.
@ ChangeOnImmutable
Changing values on immutable objects is not allowed.
@ XmpMetadataError
Error while creating or reading XMP metadata.
@ MaxRecursionReached
Reached maximum recursion depth.
@ FileNotFound
A file was not found or cannot be opened.
@ InvalidHandle
Unexpected null pointer or invalid state.
@ InvalidDataType
The passed datatype is invalid or was not recognized.
@ InvalidContentStream
The content stream is invalid due to mismatched context pairing or other problems.
@ IOError
Tried to do something unsupported to an I/O device like seek a non-seekable input device.
@ InvalidStrokeStyle
Invalid stroke style during drawing.
@ FlateError
Error in zlib.
@ UnsupportedFontFormat
This font format is not supported by PoDoFo.
@ InvalidTrailer
The PDF file has no or an invalid trailer.
@ InvalidObject
Invalid object or none none was found.
@ UnsupportedFilter
The requested filter is not yet implemented.
@ UnsupportedImageFormat
This image format is not supported by PoDoFo.
@ FreeTypeError
Error in FreeType.
@ InternalLogic
An internal sanity check or assertion failed.
@ ItemAlreadyPresent
An item to be inserted is already in this container.
@ Unknown
Unknown error.
@ InvalidNumber
A number was expected in the PDF file, but the read string is no number.
@ InvalidPassword
The password used to open the PDF file was invalid.
@ InvalidPredictor
Invalid or unimplemented predictor.
@ NotImplemented
This feature is currently not implemented.
@ OpenSSLError
OpenSSL error.
@ UnsupportedPixelFormat
This pixel format is not supported by PoDoFo.
@ InvalidName
The specified Name is not valid in this context.
@ InvalidFontData
The font file is invalid.
@ OutOfMemory
Not enough memory to complete an operation.
@ ObjectNotFound
An object was requested but was not found.
@ WrongDestinationType
The requested field is not available for the given destination type.
@ InvalidEncoding
Invalid encoding information.
@ InvalidPDF
The file is no PDF file.
@ InvalidStream
The stream is invalid.
@ CannotConvertColor
This color format cannot be converted.
@ InvalidEncryptionDict
The encryption dictionary is invalid or misses a required key.
@ InvalidEOFToken
The PDF file has no or an invalid EOF marker.
@ ValueOutOfRange
The specified memory is out of the allowed range.
@ UnexpectedEOF
End of file was reached but data was expected.