X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fexceptions.h;h=277355117ee097f86dce6d1d2c084436e8def4db;hb=7339bd0457584dc8996a472ee7264a59a779c68e;hp=8ef09875ba89383af42fe35ad2cdd99b08fa574a;hpb=3fc9a435a720d8b2abd78c1bdc7b34bc635ad797;p=dcpomatic.git diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h index 8ef09875b..277355117 100644 --- a/src/lib/exceptions.h +++ b/src/lib/exceptions.h @@ -17,13 +17,21 @@ */ +#ifndef DVDOMATIC_EXCEPTIONS_H +#define DVDOMATIC_EXCEPTIONS_H + /** @file src/exceptions.h * @brief Our exceptions. */ #include -#include #include +#include +#include +extern "C" { +#include +} +#include "compose.hpp" /** @class StringError * @brief A parent class for exceptions using messages held in a std::string @@ -135,12 +143,7 @@ public: 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 (); + _what = String::compose ("could not read from file %1 (%2)", f, strerror (e)); } }; @@ -156,12 +159,7 @@ public: 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 (); + _what = String::compose ("could not write to file %1 (%2)", f, strerror (e)); } }; @@ -225,18 +223,39 @@ public: {} }; -class PlayError : public StringError +class PixelFormatError : public StringError { public: - PlayError (std::string s) - : StringError (s) + PixelFormatError (std::string o, AVPixelFormat f) + : StringError (String::compose ("Cannot handle pixel format %1 during %2", f, o)) {} }; -class DVDError : public StringError +class ExceptionStore { public: - DVDError (std::string s) - : StringError (s) - {} + 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