/src/poco/XML/include/Poco/SAX/SAXException.h
Line | Count | Source |
1 | | // |
2 | | // SAXException.h |
3 | | // |
4 | | // Library: XML |
5 | | // Package: SAX |
6 | | // Module: SAX |
7 | | // |
8 | | // SAX exception classes. |
9 | | // |
10 | | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
11 | | // and Contributors. |
12 | | // |
13 | | // SPDX-License-Identifier: BSL-1.0 |
14 | | // |
15 | | |
16 | | |
17 | | #ifndef SAX_SAXException_INCLUDED |
18 | | #define SAX_SAXException_INCLUDED |
19 | | |
20 | | |
21 | | #include "Poco/XML/XML.h" |
22 | | #include "Poco/XML/XMLException.h" |
23 | | #include "Poco/XML/XMLString.h" |
24 | | |
25 | | |
26 | | namespace Poco::XML { |
27 | | |
28 | | |
29 | | POCO_DECLARE_EXCEPTION(XML_API, SAXException, XMLException) |
30 | | /// The base class for all SAX-related exceptions like SAXParseException, |
31 | | /// SAXNotRecognizedException or SAXNotSupportedException. |
32 | | /// |
33 | | /// This class can contain basic error or warning information from either the XML parser |
34 | | /// or the application: a parser writer or application writer can subclass it to provide |
35 | | /// additional functionality. SAX handlers may throw this exception or any exception subclassed |
36 | | /// from it. |
37 | | /// |
38 | | /// If the application needs to pass through other types of exceptions, it must wrap those exceptions |
39 | | /// in a SAXException or an exception derived from a SAXException. |
40 | | /// |
41 | | /// If the parser or application needs to include information about a specific location in an XML |
42 | | /// document, it should use the SAXParseException subclass. |
43 | | |
44 | | |
45 | | POCO_DECLARE_EXCEPTION(XML_API, SAXNotRecognizedException, SAXException) |
46 | | /// Exception class for an unrecognized identifier. |
47 | | /// |
48 | | /// An XMLReader will throw this exception when it finds an unrecognized feature or property |
49 | | /// identifier; SAX applications and extensions may use this class for other, similar purposes. |
50 | | |
51 | | |
52 | | POCO_DECLARE_EXCEPTION(XML_API, SAXNotSupportedException, SAXException) |
53 | | /// Exception class for an unsupported operation. |
54 | | /// |
55 | | /// An XMLReader will throw this exception when it recognizes a feature or property identifier, |
56 | | /// but cannot perform the requested operation (setting a state or value). Other SAX2 applications |
57 | | /// and extensions may use this class for similar purposes. |
58 | | |
59 | | |
60 | | class Locator; |
61 | | |
62 | | |
63 | | class XML_API SAXParseException: public SAXException |
64 | | /// Encapsulate an XML parse error or warning. |
65 | | /// |
66 | | /// This exception may include information for locating the error in the original XML document, |
67 | | /// as if it came from a Locator object. Note that although the application will receive a |
68 | | /// SAXParseException as the argument to the handlers in the ErrorHandler interface, the application |
69 | | /// is not actually required to throw the exception; instead, it can simply read the information in it |
70 | | /// and take a different action. |
71 | | /// |
72 | | /// Since this exception is a subclass of SAXException, it inherits the ability to wrap another exception. |
73 | | { |
74 | | public: |
75 | | SAXParseException(const std::string& msg, const Locator& loc); |
76 | | /// Create a new SAXParseException from a message and a Locator. |
77 | | |
78 | | SAXParseException(const std::string& msg, const Locator& loc, const Poco::Exception& exc); |
79 | | /// Wrap an existing exception in a SAXParseException. |
80 | | |
81 | | SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber); |
82 | | /// Create a new SAXParseException with an embedded exception. |
83 | | /// |
84 | | /// This constructor is most useful for parser writers. |
85 | | /// All parameters except the message are as if they were provided by a Locator. |
86 | | /// For example, if the system identifier is a URL (including relative filename), |
87 | | /// the caller must resolve it fully before creating the exception. |
88 | | |
89 | | SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber, const Poco::Exception& exc); |
90 | | /// Create a new SAXParseException. |
91 | | /// |
92 | | /// This constructor is most useful for parser writers. |
93 | | /// All parameters except the message are as if they were provided by a Locator. |
94 | | /// For example, if the system identifier is a URL (including relative filename), |
95 | | /// the caller must resolve it fully before creating the exception. |
96 | | |
97 | | SAXParseException(const SAXParseException& exc); |
98 | | /// Creates a new SAXParseException from another one. |
99 | | |
100 | | ~SAXParseException() noexcept; |
101 | | /// Destroy the exception. |
102 | | |
103 | | SAXParseException& operator = (const SAXParseException& exc); |
104 | | /// Assignment operator. |
105 | | |
106 | | const char* name() const noexcept; |
107 | | /// Returns a static string describing the exception. |
108 | | |
109 | | const char* className() const noexcept; |
110 | | /// Returns the name of the exception class. |
111 | | |
112 | | Poco::Exception* clone() const; |
113 | | /// Creates an exact copy of the exception. |
114 | | |
115 | | void rethrow() const; |
116 | | /// (Re)Throws the exception. |
117 | | |
118 | | const XMLString& getPublicId() const; |
119 | | /// Get the public identifier of the entity where the exception occurred. |
120 | | |
121 | | const XMLString& getSystemId() const; |
122 | | /// Get the system identifier of the entity where the exception occurred. |
123 | | |
124 | | int getLineNumber() const; |
125 | | /// The line number of the end of the text where the exception occurred. |
126 | | /// The first line is line 1. |
127 | | |
128 | | int getColumnNumber() const; |
129 | | /// The column number of the end of the text where the exception occurred. |
130 | | /// The first column in a line is position 1. |
131 | | |
132 | | protected: |
133 | | static std::string buildMessage(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber); |
134 | | |
135 | | private: |
136 | | SAXParseException(); |
137 | | |
138 | | XMLString _publicId; |
139 | | XMLString _systemId; |
140 | | int _lineNumber; |
141 | | int _columnNumber; |
142 | | }; |
143 | | |
144 | | |
145 | | // |
146 | | // inlines |
147 | | // |
148 | | inline const XMLString& SAXParseException::getPublicId() const |
149 | 0 | { |
150 | 0 | return _publicId; |
151 | 0 | } |
152 | | |
153 | | |
154 | | inline const XMLString& SAXParseException::getSystemId() const |
155 | 0 | { |
156 | 0 | return _systemId; |
157 | 0 | } |
158 | | |
159 | | |
160 | | inline int SAXParseException::getLineNumber() const |
161 | 0 | { |
162 | 0 | return _lineNumber; |
163 | 0 | } |
164 | | |
165 | | |
166 | | inline int SAXParseException::getColumnNumber() const |
167 | 0 | { |
168 | 0 | return _columnNumber; |
169 | 0 | } |
170 | | |
171 | | |
172 | | } // namespace Poco::XML |
173 | | |
174 | | |
175 | | #endif // SAX_SAXException_INCLUDED |