Tidying.
[libdcp.git] / src / exceptions.h
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     libdcp is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34
35 /** @file  src/exceptions.h
36  *  @brief Exceptions thrown by libdcp
37  */
38
39
40 #ifndef LIBDCP_EXCEPTIONS_H
41 #define LIBDCP_EXCEPTIONS_H
42
43
44 #include <boost/filesystem.hpp>
45 #include <boost/optional.hpp>
46
47
48 namespace dcp
49 {
50
51
52 /** @class FileError
53  *  @brief An exception related to a file
54  */
55 class FileError : public std::runtime_error
56 {
57 public:
58         FileError (std::string message, boost::filesystem::path filename, int number);
59         ~FileError () throw () {}
60
61         /** @return filename of file that was involved */
62         boost::filesystem::path filename () const {
63                 return _filename;
64         }
65
66         /** @return error number of the error */
67         int number () const {
68                 return _number;
69         }
70
71 private:
72         /** filename of file that was involved */
73         boost::filesystem::path _filename;
74         int _number;
75 };
76
77
78 /** @class MXFFileError
79  *  @brief An exception related to an MXF file
80  */
81 class MXFFileError : public FileError
82 {
83 public:
84         MXFFileError (std::string message, boost::filesystem::path filename, int number)
85                 : FileError (message, filename, number)
86         {}
87 };
88
89
90 /** @class MiscError
91  *  @brief A miscellaneous exception
92  */
93 class MiscError : public std::runtime_error
94 {
95 public:
96         explicit MiscError (std::string message)
97                 : std::runtime_error (message)
98         {}
99 };
100
101
102 /** @class ReadError
103  *  @brief Any error that occurs when reading data from a DCP
104  */
105 class ReadError : public std::runtime_error
106 {
107 public:
108         explicit ReadError (std::string message)
109                 : std::runtime_error(message)
110                 , _message(message)
111         {}
112
113         ReadError (std::string message, std::string detail);
114
115         ~ReadError() throw () {}
116
117         std::string message () const {
118                 return _message;
119         }
120
121         boost::optional<std::string> detail () const {
122                 return _detail;
123         }
124
125 private:
126         std::string _message;
127         boost::optional<std::string> _detail;
128 };
129
130
131 /** @class J2KDecompressionError
132  *  @brief An error that occurs during decompression of JPEG2000 data
133  */
134 class J2KDecompressionError : public ReadError
135 {
136 public:
137         explicit J2KDecompressionError (std::string message)
138                 : ReadError (message)
139         {}
140 };
141
142
143 class BadContentKindError : public ReadError
144 {
145 public:
146         BadContentKindError (std::string content_kind);
147 };
148
149
150 /** @class XMLError
151  *  @brief An XML error
152  */
153 class XMLError : public std::runtime_error
154 {
155 public:
156         explicit XMLError (std::string message)
157                 : std::runtime_error (message)
158         {}
159 };
160
161
162 /** @class UnresolvedRefError
163  *  @brief An exception caused by a reference (by UUID) to something which is not known
164  */
165 class UnresolvedRefError : public std::runtime_error
166 {
167 public:
168         explicit UnresolvedRefError (std::string id);
169 };
170
171
172 /** @class TimeFormatError
173  *  @brief A an error with a string passed to LocalTime
174  */
175 class TimeFormatError : public std::runtime_error
176 {
177 public:
178         explicit TimeFormatError (std::string bad_time);
179 };
180
181
182 /** @class NotEncryptedError
183  *  @brief An error raised when creating a DecryptedKDM object for assets that are not
184  *  encrypted
185  */
186 class NotEncryptedError : public std::runtime_error
187 {
188 public:
189         explicit NotEncryptedError (std::string const & what);
190         ~NotEncryptedError () throw () {}
191 };
192
193
194 /** @class ProgrammingError
195  *  @brief An exception thrown when a DCP_ASSERT fails; something that should not happen
196  */
197 class ProgrammingError : public std::runtime_error
198 {
199 public:
200         ProgrammingError (std::string file, int line);
201 };
202
203
204 class KDMDecryptionError : public std::runtime_error
205 {
206 public:
207         KDMDecryptionError (std::string message, int cipher_length, int modulus_dmax);
208 };
209
210
211 class KDMFormatError : public std::runtime_error
212 {
213 public:
214         KDMFormatError (std::string message);
215 };
216
217
218 class CertificateChainError : public std::runtime_error
219 {
220 public:
221         CertificateChainError (std::string message);
222 };
223
224
225 class MissingSubtitleImageError : public std::runtime_error
226 {
227 public:
228         MissingSubtitleImageError (std::string id);
229 };
230
231
232 class BadKDMDateError : public std::runtime_error
233 {
234 public:
235         BadKDMDateError (bool starts_too_early);
236
237         bool starts_too_early () const {
238                 return _starts_too_early;
239         }
240
241 private:
242         bool _starts_too_early;
243 };
244
245
246 class StartCompressionError : public std::runtime_error
247 {
248 public:
249         explicit StartCompressionError (boost::optional<int> code = boost::optional<int>());
250         ~StartCompressionError () throw () {}
251
252         boost::optional<int> code () const {
253                 return _code;
254         }
255
256 private:
257         boost::optional<int> _code;
258 };
259
260
261 class CombineError : public std::runtime_error
262 {
263 public:
264         explicit CombineError (std::string message);
265 };
266
267
268 class LanguageTagError : public std::runtime_error
269 {
270 public:
271         LanguageTagError (std::string message);
272 };
273
274
275 class BadSettingError : public std::runtime_error
276 {
277 public:
278         BadSettingError (std::string message);
279 };
280
281
282 class DuplicateIdError : public std::runtime_error
283 {
284 public:
285         DuplicateIdError (std::string message);
286 };
287
288
289 class MainSoundConfigurationError : public std::runtime_error
290 {
291 public:
292         MainSoundConfigurationError (std::string s);
293 };
294
295
296 class UnknownChannelIdError : public std::runtime_error
297 {
298 public:
299         UnknownChannelIdError (std::string s);
300 };
301
302
303 class NoReelsError : public std::runtime_error
304 {
305 public:
306         NoReelsError ();
307 };
308
309
310 }
311
312
313 #endif