X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fexceptions.h;h=ddd1e36035f9dfb6a5e71827a2b47f8c978da3f0;hp=38452ffc02b7c0867596cb55787a77c29eeafc01;hb=5eb8b5c3a1566aef638e9d9df03b88d320735092;hpb=74fe68e5895654e27a7cf8097917c1e95fa89519 diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h index 38452ffc0..ddd1e3603 100644 --- a/src/lib/exceptions.h +++ b/src/lib/exceptions.h @@ -1,19 +1,20 @@ /* Copyright (C) 2012-2014 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + DCP-o-matic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with DCP-o-matic. If not, see . */ @@ -24,72 +25,55 @@ #ifndef DCPOMATIC_EXCEPTIONS_H #define DCPOMATIC_EXCEPTIONS_H -#include -#include -#include -#include -#include extern "C" { #include } +#include +#include +#include -/** @class StringError - * @brief A parent class for exceptions using messages held in a std::string +/** @class DecodeError + * @brief A low-level problem with the decoder (possibly due to the nature + * of a source file). */ -class StringError : public std::exception +class DecodeError : public std::runtime_error { public: - /** @param w Error message */ - StringError (std::string w) { - _what = w; - } - - virtual ~StringError () throw () {} - - /** @return error message */ - char const * what () const throw () { - return _what.c_str (); - } - -protected: - /** error message */ - std::string _what; + explicit DecodeError (std::string s) + : std::runtime_error (s) + {} }; -/** @class DecodeError - * @brief A low-level problem with the decoder (possibly due to the nature - * of a source file). - */ -class DecodeError : public StringError +class CryptoError : public std::runtime_error { public: - DecodeError (std::string s) - : StringError (s) + explicit CryptoError (std::string s) + : std::runtime_error (s) {} }; /** @class EncodeError * @brief A low-level problem with an encoder. */ -class EncodeError : public StringError +class EncodeError : public std::runtime_error { public: - EncodeError (std::string s) - : StringError (s) + explicit EncodeError (std::string s) + : std::runtime_error (s) {} }; /** @class FileError. * @brief Parent class for file-related errors. */ -class FileError : public StringError +class FileError : public std::runtime_error { public: /** @param m Error message. * @param f Name of the file that this exception concerns. */ FileError (std::string m, boost::filesystem::path f) - : StringError (m) + : std::runtime_error (m) , _file (f) {} @@ -105,11 +89,11 @@ private: boost::filesystem::path _file; }; -class JoinError : public StringError +class JoinError : public std::runtime_error { public: - JoinError (std::string s) - : StringError (s) + explicit JoinError (std::string s) + : std::runtime_error (s) {} }; @@ -119,21 +103,19 @@ public: class OpenFileError : public FileError { public: - /** @param f File that we were trying to open */ - OpenFileError (boost::filesystem::path f); -}; - -/** @class CreateFileError. - * @brief Indicates that some error occurred when trying to create a file. - */ -class CreateFileError : public FileError -{ -public: - /** @param f File that we were trying to create */ - CreateFileError (boost::filesystem::path f); + enum Mode { + READ, + WRITE, + READ_WRITE + }; + + /** @param f File that we were trying to open. + * @param error Code of error that occurred. + * @param mode Mode that we tried to open the file in. + */ + OpenFileError (boost::filesystem::path f, int error, Mode mode); }; - /** @class ReadFileError. * @brief Indicates that some error occurred when trying to read from a file */ @@ -161,14 +143,14 @@ public: /** @class SettingError. * @brief Indicates that something is wrong with a setting. */ -class SettingError : public StringError +class SettingError : public std::runtime_error { public: /** @param s Name of setting that was required. * @param m Message. */ SettingError (std::string s, std::string m) - : StringError (m) + : std::runtime_error (m) , _setting (s) {} @@ -190,7 +172,7 @@ class MissingSettingError : public SettingError { public: /** @param s Name of setting that was required */ - MissingSettingError (std::string s); + explicit MissingSettingError (std::string s); }; /** @class BadSettingError @@ -199,7 +181,9 @@ public: class BadSettingError : public SettingError { public: - /** @param s Name of setting that is bad */ + /** @param s Name of setting that is bad. + * @param m Error message. + */ BadSettingError (std::string s, std::string m) : SettingError (s, m) {} @@ -208,85 +192,110 @@ public: /** @class NetworkError * @brief Indicates some problem with communication on the network. */ -class NetworkError : public StringError +class NetworkError : public std::runtime_error { public: - NetworkError (std::string s) - : StringError (s) + explicit NetworkError (std::string s) + : std::runtime_error (s) {} }; /** @class KDMError * @brief A problem with a KDM. */ -class KDMError : public StringError +class KDMError : public std::runtime_error { public: - KDMError (std::string s) - : StringError (s) - {} + KDMError (std::string s, std::string d); + ~KDMError () throw() {} + + std::string summary () const { + return _summary; + } + + std::string detail () const { + return _detail; + } + +private: + std::string _summary; + std::string _detail; }; /** @class PixelFormatError * @brief A problem with an unsupported pixel format. */ -class PixelFormatError : public StringError +class PixelFormatError : public std::runtime_error { public: PixelFormatError (std::string o, AVPixelFormat f); }; -/** @class SubRipError - * @brief An error that occurs while parsing a SubRip file. +/** @class TextSubtitleError + * @brief An error that occurs while parsing a TextSubtitleError file. */ -class SubRipError : public FileError +class TextSubtitleError : public FileError { public: - SubRipError (std::string, std::string, boost::filesystem::path); + TextSubtitleError (std::string, std::string, boost::filesystem::path); }; -/** @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 +class DCPError : public std::runtime_error { public: - void rethrow () { - boost::mutex::scoped_lock lm (_mutex); - if (_exception) { - boost::rethrow_exception (_exception); - _exception = boost::exception_ptr (); - } - } + explicit DCPError (std::string s) + : std::runtime_error (s) + {} +}; -protected: - - void store_current () { - boost::mutex::scoped_lock lm (_mutex); - _exception = boost::current_exception (); - } +class InvalidSignerError : public std::runtime_error +{ +public: + InvalidSignerError (); + explicit InvalidSignerError (std::string reason); +}; -private: - boost::exception_ptr _exception; - mutable boost::mutex _mutex; +class ProgrammingError : public std::runtime_error +{ +public: + ProgrammingError (std::string file, int line, std::string message = ""); +}; + +class TextEncodingError : public std::runtime_error +{ +public: + explicit TextEncodingError (std::string s) + : std::runtime_error (s) + {} +}; + +class MetadataError : public std::runtime_error +{ +public: + explicit MetadataError (std::string s) + : std::runtime_error (s) + {} +}; + +class OldFormatError : public std::runtime_error +{ +public: + explicit OldFormatError (std::string s) + : std::runtime_error (s) + {} +}; + +class KDMAsContentError : public std::runtime_error +{ +public: + KDMAsContentError (); +}; + +class GLError : public std::runtime_error +{ +public: + GLError (char const * last, int e); }; - #endif