X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fexceptions.h;h=52f257a8d3f558550ccba9724dfe612e3eca55c0;hb=5ea52a08f45b0cb8b8fe7221244cdcdeeaca0ed7;hp=6b567805b1fcd46ac7d1c78c13423624ef1f5b3d;hpb=7a8f7e87d631adec94b6b2e61e524ee9424e8284;p=dcpomatic.git diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h index 6b567805b..52f257a8d 100644 --- a/src/lib/exceptions.h +++ b/src/lib/exceptions.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2014 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,13 +17,21 @@ */ -/** @file src/exceptions.h +/** @file src/lib/exceptions.h * @brief Our exceptions. */ +#ifndef DCPOMATIC_EXCEPTIONS_H +#define DCPOMATIC_EXCEPTIONS_H + #include -#include #include +#include +#include +#include +extern "C" { +#include +} /** @class StringError * @brief A parent class for exceptions using messages held in a std::string @@ -77,21 +85,33 @@ public: class FileError : public StringError { public: - FileError (std::string m, std::string f) + /** @param m Error message. + * @param f Name of the file that this exception concerns. + */ + FileError (std::string m, boost::filesystem::path f) : StringError (m) , _file (f) {} virtual ~FileError () throw () {} - std::string file () const { + /** @return name of the file that this exception concerns */ + boost::filesystem::path file () const { return _file; } private: - std::string _file; + /** name of the file that this exception concerns */ + boost::filesystem::path _file; +}; + +class JoinError : public StringError +{ +public: + JoinError (std::string s) + : StringError (s) + {} }; - /** @class OpenFileError. * @brief Indicates that some error occurred when trying to open a file. @@ -100,9 +120,7 @@ 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) - {} + OpenFileError (boost::filesystem::path f); }; /** @class CreateFileError. @@ -112,9 +130,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 (boost::filesystem::path f); }; @@ -127,16 +143,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 (boost::filesystem::path f, int e = 0); }; /** @class WriteFileError. @@ -148,16 +155,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 (boost::filesystem::path f, int e); }; /** @class SettingError. @@ -192,9 +190,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 @@ -209,7 +205,7 @@ public: {} }; -/** @class NetworkError. +/** @class NetworkError * @brief Indicates some problem with communication on the network. */ class NetworkError : public StringError @@ -220,18 +216,89 @@ public: {} }; -class PlayError : public StringError +/** @class KDMError + * @brief A problem with a KDM. + */ +class KDMError : public StringError { public: - PlayError (std::string s) + KDMError (std::string s) : StringError (s) {} }; -class DVDError : public StringError +/** @class PixelFormatError + * @brief A problem with an unsupported pixel format. + */ +class PixelFormatError : public StringError +{ +public: + PixelFormatError (std::string o, AVPixelFormat f); +}; + +/** @class SubRipError + * @brief An error that occurs while parsing a SubRip file. + */ +class SubRipError : public FileError +{ +public: + SubRipError (std::string, std::string, boost::filesystem::path); +}; + +class DCPError : public StringError { public: - DVDError (std::string s) + DCPError (std::string s) : StringError (s) {} }; + +class InvalidSignerError : public StringError +{ +public: + InvalidSignerError (); +}; + +/** @class ExceptionStore + * @brief A parent class for classes which have a need to catch and + * re-throw exceptions. + * + * This is intended for classes which run their own thread; they should do + * something like + * + * void my_thread () + * try { + * // do things which might throw exceptions + * } catch (...) { + * store_current (); + * } + * + * and then in another thread call rethrow(). If any + * exception was thrown by my_thread it will be stored by + * store_current() and then rethrow() will re-throw it where + * it can be handled. + */ +class ExceptionStore +{ +public: + void rethrow () { + boost::mutex::scoped_lock lm (_mutex); + if (_exception) { + boost::rethrow_exception (_exception); + _exception = boost::exception_ptr (); + } + } + +protected: + + void store_current () { + boost::mutex::scoped_lock lm (_mutex); + _exception = boost::current_exception (); + } + +private: + boost::exception_ptr _exception; + mutable boost::mutex _mutex; +}; + +#endif