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 DVDOMATIC_EXCEPTIONS_H
21 #define DVDOMATIC_EXCEPTIONS_H
23 /** @file src/exceptions.h
24 * @brief Our exceptions.
29 #include <boost/exception/all.hpp>
30 #include <boost/thread.hpp>
32 #include <libavutil/pixfmt.h>
35 /** @class StringError
36 * @brief A parent class for exceptions using messages held in a std::string
38 class StringError : public std::exception
41 /** @param w Error message */
42 StringError (std::string w) {
46 virtual ~StringError () throw () {}
48 /** @return error message */
49 char const * what () const throw () {
50 return _what.c_str ();
58 /** @class DecodeError
59 * @brief A low-level problem with the decoder (possibly due to the nature
62 class DecodeError : public StringError
65 DecodeError (std::string s)
70 /** @class EncodeError
71 * @brief A low-level problem with an encoder.
73 class EncodeError : public StringError
76 EncodeError (std::string s)
82 * @brief Parent class for file-related errors.
84 class FileError : public StringError
87 /** @param m Error message.
88 * @param f Name of the file that this exception concerns.
90 FileError (std::string m, std::string f)
95 virtual ~FileError () throw () {}
97 /** @return name of the file that this exception concerns */
98 std::string file () const {
103 /** name of the file that this exception concerns */
108 /** @class OpenFileError.
109 * @brief Indicates that some error occurred when trying to open a file.
111 class OpenFileError : public FileError
114 /** @param f File that we were trying to open */
115 OpenFileError (std::string f);
118 /** @class CreateFileError.
119 * @brief Indicates that some error occurred when trying to create a file.
121 class CreateFileError : public FileError
124 /** @param f File that we were trying to create */
125 CreateFileError (std::string f);
129 /** @class ReadFileError.
130 * @brief Indicates that some error occurred when trying to read from a file
132 class ReadFileError : public FileError
135 /** @param f File that we were trying to read from.
136 * @param e errno value, or 0.
138 ReadFileError (std::string f, int e = 0);
141 /** @class WriteFileError.
142 * @brief Indicates that some error occurred when trying to write to a file
144 class WriteFileError : public FileError
147 /** @param f File that we were trying to write to.
148 * @param e errno value, or 0.
150 WriteFileError (std::string f, int e);
153 /** @class SettingError.
154 * @brief Indicates that something is wrong with a setting.
156 class SettingError : public StringError
159 /** @param s Name of setting that was required.
162 SettingError (std::string s, std::string m)
167 virtual ~SettingError () throw () {}
169 /** @return name of setting in question */
170 std::string setting () const {
175 std::string _setting;
178 /** @class MissingSettingError.
179 * @brief Indicates that a Film is missing a setting that is required for some operation.
181 class MissingSettingError : public SettingError
184 /** @param s Name of setting that was required */
185 MissingSettingError (std::string s);
188 /** @class BadSettingError
189 * @brief Indicates that a setting is bad in some way.
191 class BadSettingError : public SettingError
194 /** @param s Name of setting that is bad */
195 BadSettingError (std::string s, std::string m)
196 : SettingError (s, m)
200 /** @class NetworkError.
201 * @brief Indicates some problem with communication on the network.
203 class NetworkError : public StringError
206 NetworkError (std::string s)
211 class PixelFormatError : public StringError
214 PixelFormatError (std::string o, AVPixelFormat f);
220 bool thrown () const {
221 boost::mutex::scoped_lock lm (_mutex);
226 boost::mutex::scoped_lock lm (_mutex);
227 boost::rethrow_exception (_exception);
232 void store_current () {
233 boost::mutex::scoped_lock lm (_mutex);
234 _exception = boost::current_exception ();
238 boost::exception_ptr _exception;
239 mutable boost::mutex _mutex;