2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 #ifndef DCPOMATIC_EXCEPTIONS_H
21 #define DCPOMATIC_EXCEPTIONS_H
23 /** @file src/exceptions.h
24 * @brief Our exceptions.
29 #include <boost/exception/all.hpp>
30 #include <boost/filesystem.hpp>
31 #include <boost/thread.hpp>
33 #include <libavutil/pixfmt.h>
36 /** @class StringError
37 * @brief A parent class for exceptions using messages held in a std::string
39 class StringError : public std::exception
42 /** @param w Error message */
43 StringError (std::string w) {
47 virtual ~StringError () throw () {}
49 /** @return error message */
50 char const * what () const throw () {
51 return _what.c_str ();
59 /** @class DecodeError
60 * @brief A low-level problem with the decoder (possibly due to the nature
63 class DecodeError : public StringError
66 DecodeError (std::string s)
71 /** @class EncodeError
72 * @brief A low-level problem with an encoder.
74 class EncodeError : public StringError
77 EncodeError (std::string s)
83 * @brief Parent class for file-related errors.
85 class FileError : public StringError
88 /** @param m Error message.
89 * @param f Name of the file that this exception concerns.
91 FileError (std::string m, boost::filesystem::path f)
96 virtual ~FileError () throw () {}
98 /** @return name of the file that this exception concerns */
99 boost::filesystem::path file () const {
104 /** name of the file that this exception concerns */
105 boost::filesystem::path _file;
108 class JoinError : public StringError
111 JoinError (std::string s)
116 /** @class OpenFileError.
117 * @brief Indicates that some error occurred when trying to open a file.
119 class OpenFileError : public FileError
122 /** @param f File that we were trying to open */
123 OpenFileError (boost::filesystem::path f);
126 /** @class CreateFileError.
127 * @brief Indicates that some error occurred when trying to create a file.
129 class CreateFileError : public FileError
132 /** @param f File that we were trying to create */
133 CreateFileError (boost::filesystem::path f);
137 /** @class ReadFileError.
138 * @brief Indicates that some error occurred when trying to read from a file
140 class ReadFileError : public FileError
143 /** @param f File that we were trying to read from.
144 * @param e errno value, or 0.
146 ReadFileError (boost::filesystem::path f, int e = 0);
149 /** @class WriteFileError.
150 * @brief Indicates that some error occurred when trying to write to a file
152 class WriteFileError : public FileError
155 /** @param f File that we were trying to write to.
156 * @param e errno value, or 0.
158 WriteFileError (boost::filesystem::path f, int e);
161 /** @class SettingError.
162 * @brief Indicates that something is wrong with a setting.
164 class SettingError : public StringError
167 /** @param s Name of setting that was required.
170 SettingError (std::string s, std::string m)
175 virtual ~SettingError () throw () {}
177 /** @return name of setting in question */
178 std::string setting () const {
183 std::string _setting;
186 /** @class MissingSettingError.
187 * @brief Indicates that a Film is missing a setting that is required for some operation.
189 class MissingSettingError : public SettingError
192 /** @param s Name of setting that was required */
193 MissingSettingError (std::string s);
196 /** @class BadSettingError
197 * @brief Indicates that a setting is bad in some way.
199 class BadSettingError : public SettingError
202 /** @param s Name of setting that is bad */
203 BadSettingError (std::string s, std::string m)
204 : SettingError (s, m)
208 /** @class NetworkError.
209 * @brief Indicates some problem with communication on the network.
211 class NetworkError : public StringError
214 NetworkError (std::string s)
219 class KDMError : public StringError
222 KDMError (std::string s)
227 class PixelFormatError : public StringError
230 PixelFormatError (std::string o, AVPixelFormat f);
236 bool thrown () const {
237 boost::mutex::scoped_lock lm (_mutex);
242 boost::mutex::scoped_lock lm (_mutex);
243 boost::rethrow_exception (_exception);
248 void store_current () {
249 boost::mutex::scoped_lock lm (_mutex);
250 _exception = boost::current_exception ();
254 boost::exception_ptr _exception;
255 mutable boost::mutex _mutex;