Better errors on open fails; remove unused exception.
[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         OpenFileError (boost::filesystem::path f, int error);
100 };
101
102 /** @class ReadFileError.
103  *  @brief Indicates that some error occurred when trying to read from a file
104  */
105 class ReadFileError : public FileError
106 {
107 public:
108         /** @param f File that we were trying to read from.
109          *  @param e errno value, or 0.
110          */
111         ReadFileError (boost::filesystem::path f, int e = 0);
112 };
113
114 /** @class WriteFileError.
115  *  @brief Indicates that some error occurred when trying to write to a file
116  */
117 class WriteFileError : public FileError
118 {
119 public:
120         /** @param f File that we were trying to write to.
121          *  @param e errno value, or 0.
122          */
123         WriteFileError (boost::filesystem::path f, int e);
124 };
125
126 /** @class SettingError.
127  *  @brief Indicates that something is wrong with a setting.
128  */
129 class SettingError : public std::runtime_error
130 {
131 public:
132         /** @param s Name of setting that was required.
133          *  @param m Message.
134          */
135         SettingError (std::string s, std::string m)
136                 : std::runtime_error (m)
137                 , _setting (s)
138         {}
139
140         virtual ~SettingError () throw () {}
141
142         /** @return name of setting in question */
143         std::string setting () const {
144                 return _setting;
145         }
146
147 private:
148         std::string _setting;
149 };
150
151 /** @class MissingSettingError.
152  *  @brief Indicates that a Film is missing a setting that is required for some operation.
153  */
154 class MissingSettingError : public SettingError
155 {
156 public:
157         /** @param s Name of setting that was required */
158         MissingSettingError (std::string s);
159 };
160
161 /** @class BadSettingError
162  *  @brief Indicates that a setting is bad in some way.
163  */
164 class BadSettingError : public SettingError
165 {
166 public:
167         /** @param s Name of setting that is bad */
168         BadSettingError (std::string s, std::string m)
169                 : SettingError (s, m)
170         {}
171 };
172
173 /** @class NetworkError
174  *  @brief Indicates some problem with communication on the network.
175  */
176 class NetworkError : public std::runtime_error
177 {
178 public:
179         NetworkError (std::string s)
180                 : std::runtime_error (s)
181         {}
182 };
183
184 /** @class KDMError
185  *  @brief A problem with a KDM.
186  */
187 class KDMError : public std::runtime_error
188 {
189 public:
190         KDMError (std::string s)
191                 : std::runtime_error (s)
192         {}
193 };
194
195 /** @class PixelFormatError
196  *  @brief A problem with an unsupported pixel format.
197  */
198 class PixelFormatError : public std::runtime_error
199 {
200 public:
201         PixelFormatError (std::string o, AVPixelFormat f);
202 };
203
204 /** @class TextSubtitleError
205  *  @brief An error that occurs while parsing a TextSubtitleError file.
206  */
207 class TextSubtitleError : public FileError
208 {
209 public:
210         TextSubtitleError (std::string, std::string, boost::filesystem::path);
211 };
212
213 class DCPError : public std::runtime_error
214 {
215 public:
216         DCPError (std::string s)
217                 : std::runtime_error (s)
218         {}
219 };
220
221 class InvalidSignerError : public std::runtime_error
222 {
223 public:
224         InvalidSignerError ();
225 };
226
227 class ProgrammingError : public std::runtime_error
228 {
229 public:
230         ProgrammingError (std::string file, int line);
231 };
232
233 class TextEncodingError : public std::runtime_error
234 {
235 public:
236         TextEncodingError (std::string s)
237                 : std::runtime_error (s)
238         {}
239 };
240
241 #endif