Even better open-file error reports.
[dcpomatic.git] / src / lib / exceptions.h
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic 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     DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 /** @file  src/lib/exceptions.h
22  *  @brief Our exceptions.
23  */
24
25 #ifndef DCPOMATIC_EXCEPTIONS_H
26 #define DCPOMATIC_EXCEPTIONS_H
27
28 extern "C" {
29 #include <libavutil/pixfmt.h>
30 }
31 #include <boost/filesystem.hpp>
32 #include <stdexcept>
33 #include <cstring>
34
35 /** @class DecodeError
36  *  @brief A low-level problem with the decoder (possibly due to the nature
37  *  of a source file).
38  */
39 class DecodeError : public std::runtime_error
40 {
41 public:
42         DecodeError (std::string s)
43                 : std::runtime_error (s)
44         {}
45 };
46
47 /** @class EncodeError
48  *  @brief A low-level problem with an encoder.
49  */
50 class EncodeError : public std::runtime_error
51 {
52 public:
53         EncodeError (std::string s)
54                 : std::runtime_error (s)
55         {}
56 };
57
58 /** @class FileError.
59  *  @brief Parent class for file-related errors.
60  */
61 class FileError : public std::runtime_error
62 {
63 public:
64         /** @param m Error message.
65          *  @param f Name of the file that this exception concerns.
66          */
67         FileError (std::string m, boost::filesystem::path f)
68                 : std::runtime_error (m)
69                 , _file (f)
70         {}
71
72         virtual ~FileError () throw () {}
73
74         /** @return name of the file that this exception concerns */
75         boost::filesystem::path file () const {
76                 return _file;
77         }
78
79 private:
80         /** name of the file that this exception concerns */
81         boost::filesystem::path _file;
82 };
83
84 class JoinError : public std::runtime_error
85 {
86 public:
87         JoinError (std::string s)
88                 : std::runtime_error (s)
89         {}
90 };
91
92 /** @class OpenFileError.
93  *  @brief Indicates that some error occurred when trying to open a file.
94  */
95 class OpenFileError : public FileError
96 {
97 public:
98         /** @param f File that we were trying to open.
99          *  @param error Code of error that occurred.
100          *  @param reading true if we were opening to read, false if opening to write.
101          */
102         OpenFileError (boost::filesystem::path f, int error, bool reading);
103 };
104
105 /** @class ReadFileError.
106  *  @brief Indicates that some error occurred when trying to read from a file
107  */
108 class ReadFileError : public FileError
109 {
110 public:
111         /** @param f File that we were trying to read from.
112          *  @param e errno value, or 0.
113          */
114         ReadFileError (boost::filesystem::path f, int e = 0);
115 };
116
117 /** @class WriteFileError.
118  *  @brief Indicates that some error occurred when trying to write to a file
119  */
120 class WriteFileError : public FileError
121 {
122 public:
123         /** @param f File that we were trying to write to.
124          *  @param e errno value, or 0.
125          */
126         WriteFileError (boost::filesystem::path f, int e);
127 };
128
129 /** @class SettingError.
130  *  @brief Indicates that something is wrong with a setting.
131  */
132 class SettingError : public std::runtime_error
133 {
134 public:
135         /** @param s Name of setting that was required.
136          *  @param m Message.
137          */
138         SettingError (std::string s, std::string m)
139                 : std::runtime_error (m)
140                 , _setting (s)
141         {}
142
143         virtual ~SettingError () throw () {}
144
145         /** @return name of setting in question */
146         std::string setting () const {
147                 return _setting;
148         }
149
150 private:
151         std::string _setting;
152 };
153
154 /** @class MissingSettingError.
155  *  @brief Indicates that a Film is missing a setting that is required for some operation.
156  */
157 class MissingSettingError : public SettingError
158 {
159 public:
160         /** @param s Name of setting that was required */
161         MissingSettingError (std::string s);
162 };
163
164 /** @class BadSettingError
165  *  @brief Indicates that a setting is bad in some way.
166  */
167 class BadSettingError : public SettingError
168 {
169 public:
170         /** @param s Name of setting that is bad */
171         BadSettingError (std::string s, std::string m)
172                 : SettingError (s, m)
173         {}
174 };
175
176 /** @class NetworkError
177  *  @brief Indicates some problem with communication on the network.
178  */
179 class NetworkError : public std::runtime_error
180 {
181 public:
182         NetworkError (std::string s)
183                 : std::runtime_error (s)
184         {}
185 };
186
187 /** @class KDMError
188  *  @brief A problem with a KDM.
189  */
190 class KDMError : public std::runtime_error
191 {
192 public:
193         KDMError (std::string s)
194                 : std::runtime_error (s)
195         {}
196 };
197
198 /** @class PixelFormatError
199  *  @brief A problem with an unsupported pixel format.
200  */
201 class PixelFormatError : public std::runtime_error
202 {
203 public:
204         PixelFormatError (std::string o, AVPixelFormat f);
205 };
206
207 /** @class TextSubtitleError
208  *  @brief An error that occurs while parsing a TextSubtitleError file.
209  */
210 class TextSubtitleError : public FileError
211 {
212 public:
213         TextSubtitleError (std::string, std::string, boost::filesystem::path);
214 };
215
216 class DCPError : public std::runtime_error
217 {
218 public:
219         DCPError (std::string s)
220                 : std::runtime_error (s)
221         {}
222 };
223
224 class InvalidSignerError : public std::runtime_error
225 {
226 public:
227         InvalidSignerError ();
228 };
229
230 class ProgrammingError : public std::runtime_error
231 {
232 public:
233         ProgrammingError (std::string file, int line);
234 };
235
236 class TextEncodingError : public std::runtime_error
237 {
238 public:
239         TextEncodingError (std::string s)
240                 : std::runtime_error (s)
241         {}
242 };
243
244 #endif