PDF SDK Documentation

Comprehensive Guide for Developers: Features, Integration, and API Reference

Loading...
Searching...
No Matches
exception.h
1// Copyright (c) 2009-2025 Avanquest Software. All rights reserved.
2
3#ifndef PDFSDK_CXX_EXCEPTION_H_INCLUDED_
4#define PDFSDK_CXX_EXCEPTION_H_INCLUDED_
5
6#include <stdexcept>
7
8#include <pdfsdk/core/init.h>
9
10#define PDF_THROW(code, message) throw PDF::Exception((code), (message))
11
12#define PDF_CHECK(expr, code, message) \
13 do { \
14 if (!(expr)) \
15 PDF_THROW((code), (message)); \
16 } while (false)
17
18#define PDF_CHECK_ERROR(pattern, code, message) \
19 do { \
20 const PDErrCode ec_avoid_double_inst = (code); \
21 PDF_CHECK(ec_avoid_double_inst == (pattern), ec_avoid_double_inst, (message)); \
22 } while (false)
23
24#define PDF_CHECK_SUCCESS(code, message) PDF_CHECK_ERROR(kPDErrSuccess, (code), (message))
25#define PDF_CHECK_SUCCESS_X(code) PDF_CHECK_ERROR(kPDErrSuccess, (code), PDGetErrMessage())
26
27namespace PDF {
28
35class Exception : public std::runtime_error {
36public:
42 Exception(PDErrCode code, const std::string& message)
43 : std::runtime_error(message)
44 , m_code(code) {
45 }
46
52 Exception(PDErrCode code, const char* message)
53 : std::runtime_error(message)
54 , m_code(code) {
55 }
56
62 PDErrCode GetErrorCode() const noexcept { return m_code; }
63
69 const char* GetErrorMessage() const noexcept { return what(); }
70
71private:
72 PDErrCode m_code;
73};
74
75} // namespace PDF
76
77#endif // PDFSDK_CXX_EXCEPTION_H_INCLUDED_
The exception class for the PDF SDK.
Definition exception.h:35
PDErrCode GetErrorCode() const noexcept
Gets the error code associated with the exception.
Definition exception.h:62
Exception(PDErrCode code, const std::string &message)
Constructs a new exception with the specified error code and message.
Definition exception.h:42
const char * GetErrorMessage() const noexcept
Gets the error message associated with the exception.
Definition exception.h:69
Exception(PDErrCode code, const char *message)
Constructs a new exception with the specified error code and message.
Definition exception.h:52
int32_t PDErrCode
Definition errors.h:44
Initialization API.