Branch data TLA Line data Source code
1 : : // Copyright (c) 2014-2022 Thomas Fussell
2 : : // Copyright (c) 2010-2015 openpyxl
3 : : // Copyright (c) 2024-2025 xlnt-community
4 : : //
5 : : // Permission is hereby granted, free of charge, to any person obtaining a copy
6 : : // of this software and associated documentation files (the "Software"), to deal
7 : : // in the Software without restriction, including without limitation the rights
8 : : // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 : : // copies of the Software, and to permit persons to whom the Software is
10 : : // furnished to do so, subject to the following conditions:
11 : : //
12 : : // The above copyright notice and this permission notice shall be included in
13 : : // all copies or substantial portions of the Software.
14 : : //
15 : : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 : : // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 : : // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 : : // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 : : // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 : : // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 : : // THE SOFTWARE
22 : : //
23 : : // @license: http://www.opensource.org/licenses/mit-license.php
24 : : // @author: see AUTHORS file
25 : :
26 : : #pragma once
27 : :
28 : : #include <stdexcept>
29 : :
30 : : #include <xlnt/xlnt_config.hpp>
31 : : #include <xlnt/cell/index_types.hpp>
32 : :
33 : : namespace xlnt {
34 : :
35 : : /// <summary>
36 : : /// Parent type of all custom exceptions thrown in this library.
37 : : /// </summary>
38 : : class XLNT_API exception : public std::runtime_error
39 : : {
40 : : public:
41 : : /// <summary>
42 : : /// Constructs an exception with a message. This message will be
43 : : /// returned by std::exception::what(), an inherited member of this class.
44 : : /// </summary>
45 : : explicit exception(const std::string &message);
46 : :
47 : : /// <summary>
48 : : /// Default copy constructor.
49 : : /// </summary>
50 [ + ]:CBC 121 : exception(const exception &) = default;
51 : :
52 : : /// <summary>
53 : : /// Destructor
54 : : /// </summary>
55 : : ~exception() override;
56 : :
57 : : /// <summary>
58 : : /// Sets the message after the xlnt::exception is constructed. This can show
59 : : /// more specific information than std::exception::what().
60 : : /// </summary>
61 : : void message(const std::string &message);
62 : :
63 : : /// <summary>
64 : : /// Gets the message containing extra information.
65 : : /// </summary>
66 : : const std::string & message();
67 : :
68 : : private:
69 : : /// <summary>
70 : : /// The exception message
71 : : /// </summary>
72 : : std::string message_;
73 : : };
74 : :
75 : : /// <summary>
76 : : /// Exception for a bad parameter value
77 : : /// </summary>
78 : : class XLNT_API invalid_parameter : public exception
79 : : {
80 : : public:
81 : : /// <summary>
82 : : /// Default constructor.
83 : : /// </summary>
84 : : explicit invalid_parameter(const char *optional_message = nullptr);
85 : :
86 : : /// <summary>
87 : : /// Default copy constructor.
88 : : /// </summary>
89 : 11 : invalid_parameter(const invalid_parameter &) = default;
90 : :
91 : : /// <summary>
92 : : /// Destructor
93 : : /// </summary>
94 : : ~invalid_parameter() override;
95 : : };
96 : :
97 : : /// <summary>
98 : : /// Exception for bad sheet names.
99 : : /// </summary>
100 : : class XLNT_API invalid_sheet_title : public exception
101 : : {
102 : : public:
103 : : /// <summary>
104 : : /// Default constructor.
105 : : /// </summary>
106 : : explicit invalid_sheet_title(const std::string &title);
107 : :
108 : : /// <summary>
109 : : /// Default copy constructor.
110 : : /// </summary>
111 : 11 : invalid_sheet_title(const invalid_sheet_title &) = default;
112 : :
113 : : /// <summary>
114 : : /// Destructor
115 : : /// </summary>
116 : : ~invalid_sheet_title() override;
117 : : };
118 : :
119 : : /// <summary>
120 : : /// Exception for trying to open a non-XLSX file.
121 : : /// </summary>
122 : : class XLNT_API invalid_file : public exception
123 : : {
124 : : public:
125 : : /// <summary>
126 : : /// Constructs an invalid_file exception thrown when attempt to access
127 : : /// the given file, containing a description of the reason.
128 : : /// </summary>
129 : : explicit invalid_file(const std::string &reason);
130 : :
131 : : /// <summary>
132 : : /// Default copy constructor.
133 : : /// </summary>
134 : 1 : invalid_file(const invalid_file &) = default;
135 : :
136 : : /// <summary>
137 : : /// Destructor
138 : : /// </summary>
139 : : ~invalid_file() override;
140 : : };
141 : :
142 : : /// <summary>
143 : : /// The data submitted which cannot be used directly in Excel files. It
144 : : /// must be removed or escaped.
145 : : /// </summary>
146 : : class XLNT_API illegal_character : public exception
147 : : {
148 : : public:
149 : : /// <summary>
150 : : /// Constructs an illegal_character exception thrown as a result of the given character.
151 : : /// </summary>
152 : : explicit illegal_character(char c);
153 : :
154 : : /// <summary>
155 : : /// Default copy constructor.
156 : : /// </summary>
157 : 29 : illegal_character(const illegal_character &) = default;
158 : :
159 : : /// <summary>
160 : : /// Destructor
161 : : /// </summary>
162 : : ~illegal_character() override;
163 : : };
164 : :
165 : : /// <summary>
166 : : /// Exception for any data type inconsistencies.
167 : : /// </summary>
168 : : class XLNT_API invalid_data_type : public exception
169 : : {
170 : : public:
171 : : /// <summary>
172 : : /// Default constructor.
173 : : /// </summary>
174 : : invalid_data_type();
175 : :
176 : : /// <summary>
177 : : /// Default copy constructor.
178 : : /// </summary>
179 : : invalid_data_type(const invalid_data_type &) = default;
180 : :
181 : : /// <summary>
182 : : /// Destructor
183 : : /// </summary>
184 : : ~invalid_data_type() override;
185 : : };
186 : :
187 : : /// <summary>
188 : : /// Exception for bad column indices in A1-style cell references.
189 : : /// </summary>
190 : : class XLNT_API invalid_column_index : public exception
191 : : {
192 : : public:
193 : : /// <summary>
194 : : /// Default constructor.
195 : : /// </summary>
196 : : invalid_column_index();
197 : :
198 : : /// <summary>
199 : : /// Default copy constructor.
200 : : /// </summary>
201 : 4 : invalid_column_index(const invalid_column_index &) = default;
202 : :
203 : : /// <summary>
204 : : /// Destructor
205 : : /// </summary>
206 : : ~invalid_column_index() override;
207 : : };
208 : :
209 : : /// <summary>
210 : : /// Exception for converting between numeric and A1-style cell references.
211 : : /// </summary>
212 : : class XLNT_API invalid_cell_reference : public exception
213 : : {
214 : : public:
215 : : /// <summary>
216 : : /// Constructs an invalid_cell_reference exception for the given column and row.
217 : : /// </summary>
218 : : invalid_cell_reference(column_t column, row_t row);
219 : :
220 : : /// <summary>
221 : : /// Constructs an invalid_cell_reference exception for the given string.
222 : : /// </summary>
223 : : explicit invalid_cell_reference(const std::string &reference_string);
224 : :
225 : : /// <summary>
226 : : /// Default copy constructor.
227 : : /// </summary>
228 : 10 : invalid_cell_reference(const invalid_cell_reference &) = default;
229 : :
230 : : /// <summary>
231 : : /// Destructor
232 : : /// </summary>
233 : : ~invalid_cell_reference() override;
234 : : };
235 : :
236 : : /// <summary>
237 : : /// Exception when setting a class's attribute to an invalid value
238 : : /// </summary>
239 : : class XLNT_API invalid_attribute : public exception
240 : : {
241 : : public:
242 : : /// <summary>
243 : : /// Constructor.
244 : : /// </summary>
245 : : explicit invalid_attribute(const char *optional_message = nullptr);
246 : :
247 : : /// <summary>
248 : : /// Default copy constructor.
249 : : /// </summary>
250 : 21 : invalid_attribute(const invalid_attribute &) = default;
251 : :
252 : : /// <summary>
253 : : /// Destructor
254 : : /// </summary>
255 : : ~invalid_attribute() override;
256 : : };
257 : :
258 : : /// <summary>
259 : : /// Exception for a key that doesn't exist in a container
260 : : /// </summary>
261 : : class XLNT_API key_not_found : public exception
262 : : {
263 : : public:
264 : : /// <summary>
265 : : /// Default constructor.
266 : : /// </summary>
267 : : key_not_found();
268 : :
269 : : /// <summary>
270 : : /// Default copy constructor.
271 : : /// </summary>
272 : 9 : key_not_found(const key_not_found &) = default;
273 : :
274 : : /// <summary>
275 : : /// Destructor
276 : : /// </summary>
277 : : ~key_not_found() override;
278 : : };
279 : :
280 : : /// <summary>
281 : : /// Exception for a workbook with no visible worksheets
282 : : /// </summary>
283 : : class XLNT_API no_visible_worksheets : public exception
284 : : {
285 : : public:
286 : : /// <summary>
287 : : /// Default constructor.
288 : : /// </summary>
289 : : no_visible_worksheets();
290 : :
291 : : /// <summary>
292 : : /// Default copy constructor.
293 : : /// </summary>
294 : : no_visible_worksheets(const no_visible_worksheets &) = default;
295 : :
296 : : /// <summary>
297 : : /// Destructor
298 : : /// </summary>
299 : : ~no_visible_worksheets() override;
300 : : };
301 : :
302 : : /// <summary>
303 : : /// Debug exception for a switch that fell through to the default case
304 : : /// </summary>
305 : : class XLNT_API unhandled_switch_case : public exception
306 : : {
307 : : public:
308 : : /// <summary>
309 : : /// Default constructor.
310 : : /// </summary>
311 : : unhandled_switch_case();
312 : :
313 : : /// <summary>
314 : : /// Default copy constructor.
315 : : /// </summary>
316 : : unhandled_switch_case(const unhandled_switch_case &) = default;
317 : :
318 : : /// <summary>
319 : : /// Destructor
320 : : /// </summary>
321 : : ~unhandled_switch_case() override;
322 : : };
323 : :
324 : : /// <summary>
325 : : /// Exception for attempting to use a feature which is not supported
326 : : /// </summary>
327 : : class XLNT_API unsupported : public exception
328 : : {
329 : : public:
330 : : /// <summary>
331 : : /// Constructs an unsupported exception with a message describing the unsupported
332 : : /// feature.
333 : : /// </summary>
334 : : explicit unsupported(const std::string &message);
335 : :
336 : : /// <summary>
337 : : /// Default copy constructor.
338 : : /// </summary>
339 : : unsupported(const unsupported &) = default;
340 : :
341 : : /// <summary>
342 : : /// Destructor
343 : : /// </summary>
344 : : ~unsupported() override;
345 : : };
346 : :
347 : : } // namespace xlnt
|