Separate ExceptionStore.
[dcpomatic.git] / src / lib / exceptions.h
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  src/lib/exceptions.h
21  *  @brief Our exceptions.
22  */
23
24 #ifndef DCPOMATIC_EXCEPTIONS_H
25 #define DCPOMATIC_EXCEPTIONS_H
26
27 extern "C" {
28 #include <libavutil/pixfmt.h>
29 }
30 #include <boost/filesystem.hpp>
31 #include <stdexcept>
32 #include <cstring>
33
34 /** @class StringError
35  *  @brief A parent class for exceptions using messages held in a std::string
36  */
37 class StringError : public std::exception
38 {
39 public:
40         /** @param w Error message */
41         StringError (std::string w)
42                 : _what (w)
43         {}
44
45         virtual ~StringError () throw () {}
46
47         /** @return error message */
48         char const * what () const throw () {
49                 return _what.c_str ();
50         }
51
52 protected:
53         /** error message */
54         std::string _what;
55 };
56
57 /** @class DecodeError
58  *  @brief A low-level problem with the decoder (possibly due to the nature
59  *  of a source file).
60  */
61 class DecodeError : public StringError
62 {
63 public:
64         DecodeError (std::string s)
65                 : StringError (s)
66         {}
67 };
68
69 /** @class EncodeError
70  *  @brief A low-level problem with an encoder.
71  */
72 class EncodeError : public StringError
73 {
74 public:
75         EncodeError (std::string s)
76                 : StringError (s)
77         {}
78 };
79
80 /** @class FileError.
81  *  @brief Parent class for file-related errors.
82  */
83 class FileError : public StringError
84 {
85 public:
86         /** @param m Error message.
87          *  @param f Name of the file that this exception concerns.
88          */
89         FileError (std::string m, boost::filesystem::path f)
90                 : StringError (m)
91                 , _file (f)
92         {}
93
94         virtual ~FileError () throw () {}
95
96         /** @return name of the file that this exception concerns */
97         boost::filesystem::path file () const {
98                 return _file;
99         }
100
101 private:
102         /** name of the file that this exception concerns */
103         boost::filesystem::path _file;
104 };
105
106 class JoinError : public StringError
107 {
108 public:
109         JoinError (std::string s)
110                 : StringError (s)
111         {}
112 };
113
114 /** @class OpenFileError.
115  *  @brief Indicates that some error occurred when trying to open a file.
116  */
117 class OpenFileError : public FileError
118 {
119 public:
120         /** @param f File that we were trying to open */
121         OpenFileError (boost::filesystem::path f);
122 };
123
124 /** @class CreateFileError.
125  *  @brief Indicates that some error occurred when trying to create a file.
126  */
127 class CreateFileError : public FileError
128 {
129 public:
130         /** @param f File that we were trying to create */
131         CreateFileError (boost::filesystem::path f);
132 };
133
134
135 /** @class ReadFileError.
136  *  @brief Indicates that some error occurred when trying to read from a file
137  */
138 class ReadFileError : public FileError
139 {
140 public:
141         /** @param f File that we were trying to read from.
142          *  @param e errno value, or 0.
143          */
144         ReadFileError (boost::filesystem::path f, int e = 0);
145 };
146
147 /** @class WriteFileError.
148  *  @brief Indicates that some error occurred when trying to write to a file
149  */
150 class WriteFileError : public FileError
151 {
152 public:
153         /** @param f File that we were trying to write to.
154          *  @param e errno value, or 0.
155          */
156         WriteFileError (boost::filesystem::path f, int e);
157 };
158
159 /** @class SettingError.
160  *  @brief Indicates that something is wrong with a setting.
161  */
162 class SettingError : public StringError
163 {
164 public:
165         /** @param s Name of setting that was required.
166          *  @param m Message.
167          */
168         SettingError (std::string s, std::string m)
169                 : StringError (m)
170                 , _setting (s)
171         {}
172
173         virtual ~SettingError () throw () {}
174
175         /** @return name of setting in question */
176         std::string setting () const {
177                 return _setting;
178         }
179
180 private:
181         std::string _setting;
182 };
183
184 /** @class MissingSettingError.
185  *  @brief Indicates that a Film is missing a setting that is required for some operation.
186  */
187 class MissingSettingError : public SettingError
188 {
189 public:
190         /** @param s Name of setting that was required */
191         MissingSettingError (std::string s);
192 };
193
194 /** @class BadSettingError
195  *  @brief Indicates that a setting is bad in some way.
196  */
197 class BadSettingError : public SettingError
198 {
199 public:
200         /** @param s Name of setting that is bad */
201         BadSettingError (std::string s, std::string m)
202                 : SettingError (s, m)
203         {}
204 };
205
206 /** @class NetworkError
207  *  @brief Indicates some problem with communication on the network.
208  */
209 class NetworkError : public StringError
210 {
211 public:
212         NetworkError (std::string s)
213                 : StringError (s)
214         {}
215 };
216
217 /** @class KDMError
218  *  @brief A problem with a KDM.
219  */
220 class KDMError : public StringError
221 {
222 public:
223         KDMError (std::string s)
224                 : StringError (s)
225         {}
226 };
227
228 /** @class PixelFormatError
229  *  @brief A problem with an unsupported pixel format.
230  */
231 class PixelFormatError : public StringError
232 {
233 public:
234         PixelFormatError (std::string o, AVPixelFormat f);
235 };
236
237 /** @class SubRipError
238  *  @brief An error that occurs while parsing a SubRip file.
239  */
240 class SubRipError : public FileError
241 {
242 public:
243         SubRipError (std::string, std::string, boost::filesystem::path);
244 };
245
246 class DCPError : public StringError
247 {
248 public:
249         DCPError (std::string s)
250                 : StringError (s)
251         {}
252 };
253
254 class InvalidSignerError : public StringError
255 {
256 public:
257         InvalidSignerError ();
258 };
259
260 class ProgrammingError : public StringError
261 {
262 public:
263         ProgrammingError (std::string file, int line);
264 };
265
266 #endif