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>
34 #include "compose.hpp"
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, std::string f)
96 virtual ~FileError () throw () {}
98 /** @return name of the file that this exception concerns */
99 std::string file () const {
104 /** name of the file that this exception concerns */
109 /** @class OpenFileError.
110 * @brief Indicates that some error occurred when trying to open a file.
112 class OpenFileError : public FileError
115 /** @param f File that we were trying to open */
116 OpenFileError (std::string f)
117 : FileError ("could not open file " + f, f)
121 /** @class CreateFileError.
122 * @brief Indicates that some error occurred when trying to create a file.
124 class CreateFileError : public FileError
127 /** @param f File that we were trying to create */
128 CreateFileError (std::string f)
129 : FileError ("could not create file " + f, f)
134 /** @class ReadFileError.
135 * @brief Indicates that some error occurred when trying to read from a file
137 class ReadFileError : public FileError
140 /** @param f File that we were trying to read from.
141 * @param e errno value, or 0.
143 ReadFileError (std::string f, int e = 0)
146 _what = String::compose ("could not read from file %1 (%2)", f, strerror (e));
150 /** @class WriteFileError.
151 * @brief Indicates that some error occurred when trying to write to a file
153 class WriteFileError : public FileError
156 /** @param f File that we were trying to write to.
157 * @param e errno value, or 0.
159 WriteFileError (std::string f, int e)
162 _what = String::compose ("could not write to file %1 (%2)", f, strerror (e));
166 /** @class SettingError.
167 * @brief Indicates that something is wrong with a setting.
169 class SettingError : public StringError
172 /** @param s Name of setting that was required.
175 SettingError (std::string s, std::string m)
180 virtual ~SettingError () throw () {}
182 /** @return name of setting in question */
183 std::string setting () const {
188 std::string _setting;
191 /** @class MissingSettingError.
192 * @brief Indicates that a Film is missing a setting that is required for some operation.
194 class MissingSettingError : public SettingError
197 /** @param s Name of setting that was required */
198 MissingSettingError (std::string s)
199 : SettingError (s, "missing required setting " + s)
203 /** @class BadSettingError
204 * @brief Indicates that a setting is bad in some way.
206 class BadSettingError : public SettingError
209 /** @param s Name of setting that is bad */
210 BadSettingError (std::string s, std::string m)
211 : SettingError (s, m)
215 /** @class NetworkError.
216 * @brief Indicates some problem with communication on the network.
218 class NetworkError : public StringError
221 NetworkError (std::string s)
226 class PixelFormatError : public StringError
229 PixelFormatError (std::string o, AVPixelFormat f)
230 : StringError (String::compose ("Cannot handle pixel format %1 during %2", f, o))
237 bool thrown () const {
238 boost::mutex::scoped_lock lm (_mutex);
243 boost::mutex::scoped_lock lm (_mutex);
244 boost::rethrow_exception (_exception);
249 void store_current () {
250 boost::mutex::scoped_lock lm (_mutex);
251 _exception = boost::current_exception ();
255 boost::exception_ptr _exception;
256 mutable boost::mutex _mutex;