X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fexceptions.h;h=3e7289a50e13e00c4c04259ff7c63bb65ba5bdce;hb=80400212e939dc2f3b987cb6df57709929aa5178;hp=61163c8d12403dc492251f3e85668b4fa9a1119e;hpb=7e2cf1a4a04828b5a57d5eb6869475a819005602;p=dcpomatic.git diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h index 61163c8d1..3e7289a50 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,79 +17,54 @@ */ -#ifndef DCPOMATIC_EXCEPTIONS_H -#define DCPOMATIC_EXCEPTIONS_H - -/** @file src/exceptions.h +/** @file src/lib/exceptions.h * @brief Our exceptions. */ -#include -#include -#include -#include -#include +#ifndef DCPOMATIC_EXCEPTIONS_H +#define DCPOMATIC_EXCEPTIONS_H + extern "C" { #include } - -/** @class StringError - * @brief A parent class for exceptions using messages held in a std::string - */ -class StringError : public std::exception -{ -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; -}; +#include +#include +#include /** @class DecodeError * @brief A low-level problem with the decoder (possibly due to the nature * of a source file). */ -class DecodeError : public StringError +class DecodeError : public std::runtime_error { public: DecodeError (std::string s) - : StringError (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) + : 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 +80,11 @@ private: boost::filesystem::path _file; }; -class JoinError : public StringError +class JoinError : public std::runtime_error { public: JoinError (std::string s) - : StringError (s) + : std::runtime_error (s) {} }; @@ -161,14 +136,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) {} @@ -205,76 +180,72 @@ public: {} }; -/** @class NetworkError. +/** @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) + : std::runtime_error (s) {} }; -class KDMError : public StringError +/** @class KDMError + * @brief A problem with a KDM. + */ +class KDMError : public std::runtime_error { public: KDMError (std::string s) - : StringError (s) + : std::runtime_error (s) {} }; -class PixelFormatError : public StringError +/** @class PixelFormatError + * @brief A problem with an unsupported pixel format. + */ +class PixelFormatError : public std::runtime_error { public: PixelFormatError (std::string o, AVPixelFormat f); }; -/** An error that occurs while parsing a SubRip file */ -class SubRipError : public FileError +/** @class TextSubtitleError + * @brief An error that occurs while parsing a TextSubtitleError file. + */ +class TextSubtitleError : public FileError { public: - SubRipError (std::string, std::string, boost::filesystem::path); + TextSubtitleError (std::string, std::string, boost::filesystem::path); }; -/** 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); - } - } + 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 (); +}; -private: - boost::exception_ptr _exception; - mutable boost::mutex _mutex; +class ProgrammingError : public std::runtime_error +{ +public: + ProgrammingError (std::string file, int line); }; - +class TextEncodingError : public std::runtime_error +{ +public: + TextEncodingError (std::string s) + : std::runtime_error (s) + {} +}; #endif