Replace StringError with the equivalent std::runtime_error.
authorCarl Hetherington <cth@carlh.net>
Tue, 20 Oct 2015 09:49:29 +0000 (10:49 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 20 Oct 2015 09:49:29 +0000 (10:49 +0100)
src/lib/cinema_kdms.cc
src/lib/dcp_examiner.cc
src/lib/exceptions.cc
src/lib/exceptions.h
src/lib/film.cc
src/lib/image.cc
src/lib/resampler.cc

index 37c9e1fb55cb5684aaba45612b8bdcc6c5ba2ba2..eb71b3202747ce862ca0977993749a7aed24df54 100644 (file)
@@ -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");
        }
 }
 
index fe2660d48508834c38f9b6c678c5259d3d9162cd..22b10ab84182f1890eb80804c29a2f97d98be6a0 100644 (file)
@@ -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<const DCPContent> 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."));
                }
        }
 }
index 399915253bf45c0f4a754b056c2eff59aeacc45e..c15e134ee598de24ba4122dbdb30385d49b6a96a 100644 (file)
@@ -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))
 {
 
 }
index 6939f81a34765b68366d5b958019299e4a3f3ab8..da87613042f18cf91fa04e32f37dea80951c30b4 100644 (file)
@@ -31,63 +31,40 @@ extern "C" {
 #include <stdexcept>
 #include <cstring>
 
-/** @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)
        {}
 };
 
index 47bcc35df5e5f4d462f1587dbd02b42132556dbf..9f766a749d656fcdac913d84c905eb02ce9fc457 100644 (file)
@@ -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<string>
 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<int> ("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");
index 4e1894ed6d3f638dbf89ea2135b9bc07404b8459..134172038fc04892615cd02af5593de2b4b626e8 100644 (file)
@@ -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);
index c18bad3ac9eccfcb7b1b9c5ea6fc286207b94d89..4010390b8e663ebf413efe09ceb10498aace41a2 100644 (file)
@@ -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));
        }
 }