X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fexceptions.h;h=6bad7c9245bbb8ae833e4202841a08a3ccfc2896;hb=5f1046a2164fff00a6fc74aecf4cacbca531d415;hp=bf8e85f0bdfb7d939f76b90ad41c4571361bd874;hpb=58bf77268a8e82e73d7f17ab2fe6dcd29370ade3;p=dcpomatic.git diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h index bf8e85f0b..6bad7c924 100644 --- a/src/lib/exceptions.h +++ b/src/lib/exceptions.h @@ -17,13 +17,20 @@ */ +#ifndef DCPOMATIC_EXCEPTIONS_H +#define DCPOMATIC_EXCEPTIONS_H + /** @file src/exceptions.h * @brief Our exceptions. */ #include -#include #include +#include +#include +extern "C" { +#include +} /** @class StringError * @brief A parent class for exceptions using messages held in a std::string @@ -105,9 +112,8 @@ class OpenFileError : public FileError { public: /** @param f File that we were trying to open */ - OpenFileError (std::string f) - : FileError ("could not open file " + f, f) - {} + /* XXX: should be boost::filesystem::path */ + OpenFileError (std::string f); }; /** @class CreateFileError. @@ -117,9 +123,7 @@ class CreateFileError : public FileError { public: /** @param f File that we were trying to create */ - CreateFileError (std::string f) - : FileError ("could not create file " + f, f) - {} + CreateFileError (std::string f); }; @@ -132,16 +136,7 @@ public: /** @param f File that we were trying to read from. * @param e errno value, or 0. */ - ReadFileError (std::string f, int e = 0) - : FileError ("", f) - { - std::stringstream s; - s << "could not read from file " << f; - if (e) { - s << " (" << strerror (e) << ")"; - } - _what = s.str (); - } + ReadFileError (std::string f, int e = 0); }; /** @class WriteFileError. @@ -153,16 +148,7 @@ public: /** @param f File that we were trying to write to. * @param e errno value, or 0. */ - WriteFileError (std::string f, int e) - : FileError ("", f) - { - std::stringstream s; - s << "could not write to file " << f; - if (e) { - s << " (" << strerror (e) << ")"; - } - _what = s.str (); - } + WriteFileError (std::string f, int e); }; /** @class SettingError. @@ -197,9 +183,7 @@ class MissingSettingError : public SettingError { public: /** @param s Name of setting that was required */ - MissingSettingError (std::string s) - : SettingError (s, "missing required setting " + s) - {} + MissingSettingError (std::string s); }; /** @class BadSettingError @@ -224,3 +208,38 @@ public: : StringError (s) {} }; + +class PixelFormatError : public StringError +{ +public: + PixelFormatError (std::string o, AVPixelFormat f); +}; + +class ExceptionStore +{ +public: + bool thrown () const { + boost::mutex::scoped_lock lm (_mutex); + return _exception; + } + + void rethrow () { + boost::mutex::scoped_lock lm (_mutex); + boost::rethrow_exception (_exception); + } + +protected: + + void store_current () { + boost::mutex::scoped_lock lm (_mutex); + _exception = boost::current_exception (); + } + +private: + boost::exception_ptr _exception; + mutable boost::mutex _mutex; +}; + + + +#endif