X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fexceptions.h;h=fe87ababcad292335b52ed07d0328c19484420bb;hb=refs%2Ftags%2Fv2.13.95;hp=b16275c20696482ffb0d322b432372d8de15b39e;hpb=bb767c7e338414beee132af3e96829c1448e214b;p=dcpomatic.git diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h index b16275c20..fe87ababc 100644 --- a/src/lib/exceptions.h +++ b/src/lib/exceptions.h @@ -1,97 +1,101 @@ /* - Copyright (C) 2012 Carl Hetherington + 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 . */ -/** @file src/exceptions.h +/** @file src/lib/exceptions.h * @brief Our exceptions. */ +#ifndef DCPOMATIC_EXCEPTIONS_H +#define DCPOMATIC_EXCEPTIONS_H + +extern "C" { +#include +} +#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: - FileError (std::string m, std::string f) - : StringError (m) + /** @param m Error message. + * @param f Name of the file that this exception concerns. + */ + FileError (std::string m, boost::filesystem::path f) + : std::runtime_error (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 std::runtime_error +{ +public: + explicit JoinError (std::string s) + : std::runtime_error (s) + {} }; - /** @class OpenFileError. * @brief Indicates that some error occurred when trying to open a file. @@ -99,22 +103,23 @@ private: 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) - {} + /** @param f File that we were trying to open. + * @param error Code of error that occurred. + * @param reading true if we were opening to read, false if opening to write. + */ + OpenFileError (boost::filesystem::path f, int error, bool reading); }; -/** @class CreateFileError. - * @brief Indicates that some error occurred when trying to create a file. +/** @class ReadFileError. + * @brief Indicates that some error occurred when trying to read from a file */ -class CreateFileError : public FileError +class ReadFileError : public FileError { public: - /** @param f File that we were trying to create */ - CreateFileError (std::string f) - : FileError ("could not create file " + f, f) - {} + /** @param f File that we were trying to read from. + * @param e errno value, or 0. + */ + ReadFileError (boost::filesystem::path f, int e = 0); }; /** @class WriteFileError. @@ -126,29 +131,20 @@ 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. * @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) {} @@ -170,9 +166,7 @@ class MissingSettingError : public SettingError { public: /** @param s Name of setting that was required */ - MissingSettingError (std::string s) - : SettingError (s, "missing required setting " + s) - {} + explicit MissingSettingError (std::string s); }; /** @class BadSettingError @@ -181,35 +175,114 @@ 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) {} }; -/** @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) + explicit NetworkError (std::string s) + : std::runtime_error (s) {} }; -class PlayError : public StringError +/** @class KDMError + * @brief A problem with a KDM. + */ +class KDMError : public std::runtime_error { public: - PlayError (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 std::runtime_error +{ +public: + PixelFormatError (std::string o, AVPixelFormat f); +}; + +/** @class TextSubtitleError + * @brief An error that occurs while parsing a TextSubtitleError file. + */ +class TextSubtitleError : public FileError +{ +public: + TextSubtitleError (std::string, std::string, boost::filesystem::path); +}; + +class DCPError : public std::runtime_error +{ +public: + explicit DCPError (std::string s) + : std::runtime_error (s) + {} +}; + +class InvalidSignerError : public std::runtime_error +{ +public: + InvalidSignerError (); + explicit InvalidSignerError (std::string reason); +}; + +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 DVDError : public StringError +class OldFormatError : public std::runtime_error { public: - DVDError (std::string s) - : StringError (s) + explicit OldFormatError (std::string s) + : std::runtime_error (s) {} }; + +class KDMAsContentError : public std::runtime_error +{ +public: + KDMAsContentError (); +}; + +#endif