From: Carl Hetherington Date: Tue, 20 Oct 2015 09:49:29 +0000 (+0100) Subject: Replace StringError with the equivalent std::runtime_error. X-Git-Tag: v2.4.13~15^2 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=e0adfd85dd7987ee2b77eea7f6d3c13885729a38 Replace StringError with the equivalent std::runtime_error. --- diff --git a/src/lib/cinema_kdms.cc b/src/lib/cinema_kdms.cc index 37c9e1fb5..eb71b3202 100644 --- a/src/lib/cinema_kdms.cc +++ b/src/lib/cinema_kdms.cc @@ -34,6 +34,7 @@ using std::list; using std::cout; using std::string; +using std::runtime_error; using boost::shared_ptr; void @@ -56,16 +57,16 @@ CinemaKDMs::make_zip_file (string film_name, boost::filesystem::path zip_file) c struct zip_source* source = zip_source_buffer (zip, kdm->c_str(), kdm->length(), 0); if (!source) { - throw StringError ("could not create ZIP source"); + throw runtime_error ("could not create ZIP source"); } if (zip_add (zip, i.filename(film_name).c_str(), source) == -1) { - throw StringError ("failed to add KDM to ZIP archive"); + throw runtime_error ("failed to add KDM to ZIP archive"); } } if (zip_close (zip) == -1) { - throw StringError ("failed to close ZIP archive"); + throw runtime_error ("failed to close ZIP archive"); } } diff --git a/src/lib/dcp_examiner.cc b/src/lib/dcp_examiner.cc index fe2660d48..22b10ab84 100644 --- a/src/lib/dcp_examiner.cc +++ b/src/lib/dcp_examiner.cc @@ -39,6 +39,7 @@ using std::list; using std::cout; +using std::runtime_error; using boost::shared_ptr; using boost::dynamic_pointer_cast; @@ -130,7 +131,7 @@ DCPExaminer::DCPExaminer (shared_ptr content) _kdm_valid = false; if (_encrypted && content->kdm ()) { /* XXX: maybe don't use an exception for this */ - throw StringError (_("The KDM does not decrypt the DCP. Perhaps it is targeted at the wrong CPL.")); + throw runtime_error (_("The KDM does not decrypt the DCP. Perhaps it is targeted at the wrong CPL.")); } } } diff --git a/src/lib/exceptions.cc b/src/lib/exceptions.cc index 399915253..c15e134ee 100644 --- a/src/lib/exceptions.cc +++ b/src/lib/exceptions.cc @@ -23,6 +23,7 @@ #include "i18n.h" using std::string; +using std::runtime_error; /** @param f File that we were trying to open */ OpenFileError::OpenFileError (boost::filesystem::path f) @@ -57,7 +58,7 @@ MissingSettingError::MissingSettingError (string s) } PixelFormatError::PixelFormatError (string o, AVPixelFormat f) - : StringError (String::compose (_("Cannot handle pixel format %1 during %2"), f, o)) + : runtime_error (String::compose (_("Cannot handle pixel format %1 during %2"), f, o)) { } @@ -69,13 +70,13 @@ SubRipError::SubRipError (string saw, string expecting, boost::filesystem::path } InvalidSignerError::InvalidSignerError () - : StringError (_("The certificate chain for signing is invalid")) + : runtime_error (_("The certificate chain for signing is invalid")) { } ProgrammingError::ProgrammingError (string file, int line) - : StringError (String::compose (_("Programming error at %1:%2"), file, line)) + : runtime_error (String::compose (_("Programming error at %1:%2"), file, line)) { } diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h index 6939f81a3..da8761304 100644 --- a/src/lib/exceptions.h +++ b/src/lib/exceptions.h @@ -31,63 +31,40 @@ extern "C" { #include #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; -}; - /** @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) {} @@ -103,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) {} }; @@ -159,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) {} @@ -206,29 +183,29 @@ 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) + : 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) + : std::runtime_error (s) {} }; /** @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); @@ -243,31 +220,31 @@ public: SubRipError (std::string, std::string, boost::filesystem::path); }; -class DCPError : public StringError +class DCPError : public std::runtime_error { public: DCPError (std::string s) - : StringError (s) + : std::runtime_error (s) {} }; -class InvalidSignerError : public StringError +class InvalidSignerError : public std::runtime_error { public: InvalidSignerError (); }; -class ProgrammingError : public StringError +class ProgrammingError : public std::runtime_error { public: ProgrammingError (std::string file, int line); }; -class TextEncodingError : public StringError +class TextEncodingError : public std::runtime_error { public: TextEncodingError (std::string s) - : StringError (s) + : std::runtime_error (s) {} }; diff --git a/src/lib/film.cc b/src/lib/film.cc index 47bcc35df..9f766a749 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -80,6 +80,7 @@ using std::make_pair; using std::cout; using std::list; using std::set; +using std::runtime_error; using boost::shared_ptr; using boost::weak_ptr; using boost::dynamic_pointer_cast; @@ -291,7 +292,7 @@ Film::make_dcp () } if (content().empty()) { - throw StringError (_("You must add some content to the DCP before creating it")); + throw runtime_error (_("You must add some content to the DCP before creating it")); } if (dcp_content_type() == 0) { @@ -370,7 +371,7 @@ list Film::read_metadata () { if (boost::filesystem::exists (file ("metadata")) && !boost::filesystem::exists (file ("metadata.xml"))) { - throw StringError (_("This film was created with an older version of DCP-o-matic, and unfortunately it cannot be loaded into this version. You will need to create a new Film, re-add your content and set it up again. Sorry!")); + throw runtime_error (_("This film was created with an older version of DCP-o-matic, and unfortunately it cannot be loaded into this version. You will need to create a new Film, re-add your content and set it up again. Sorry!")); } cxml::Document f ("Metadata"); @@ -378,7 +379,7 @@ Film::read_metadata () _state_version = f.number_child ("Version"); if (_state_version > current_state_version) { - throw StringError (_("This film was created with a newer version of DCP-o-matic, and it cannot be loaded into this version. Sorry!")); + throw runtime_error (_("This film was created with a newer version of DCP-o-matic, and it cannot be loaded into this version. Sorry!")); } _name = f.string_child ("Name"); diff --git a/src/lib/image.cc b/src/lib/image.cc index 4e1894ed6..134172038 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -43,6 +43,7 @@ using std::min; using std::cout; using std::cerr; using std::list; +using std::runtime_error; using boost::shared_ptr; using dcp::Size; @@ -138,7 +139,7 @@ Image::crop_scale_window ( ); if (!scale_context) { - throw StringError (N_("Could not allocate SwsContext")); + throw runtime_error (N_("Could not allocate SwsContext")); } DCPOMATIC_ASSERT (yuv_to_rgb < dcp::YUV_TO_RGB_COUNT); diff --git a/src/lib/resampler.cc b/src/lib/resampler.cc index c18bad3ac..4010390b8 100644 --- a/src/lib/resampler.cc +++ b/src/lib/resampler.cc @@ -30,6 +30,7 @@ using std::cout; using std::pair; using std::make_pair; +using std::runtime_error; using boost::shared_ptr; /** @param in Input sampling rate (Hz) @@ -45,7 +46,7 @@ Resampler::Resampler (int in, int out, int channels, bool fast) int error; _src = src_new (fast ? SRC_LINEAR : SRC_SINC_BEST_QUALITY, _channels, &error); if (!_src) { - throw StringError (String::compose (N_("could not create sample-rate converter (%1)"), error)); + throw runtime_error (String::compose (N_("could not create sample-rate converter (%1)"), error)); } }