From 5a843c4c224051237105a6e8de472ae9a216c001 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 16 Dec 2015 20:40:21 +0000 Subject: Replace use of cassert with exceptions. --- src/exceptions.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/exceptions.cc (limited to 'src/exceptions.cc') diff --git a/src/exceptions.cc b/src/exceptions.cc new file mode 100644 index 0000000..f33a1e2 --- /dev/null +++ b/src/exceptions.cc @@ -0,0 +1,30 @@ +/* + Copyright (C) 2014-2015 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 + 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, + 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. + +*/ + +#include "compose.hpp" +#include "exceptions.h" + +using std::string; +using namespace sub; + +ProgrammingError::ProgrammingError (string file, int line) + : MessageError (String::compose ("Programming error at %1:%2", file, line)) +{ + +} -- cgit v1.2.3 From 44ff188fa75cb7954fb1b9bec6b1cb03d8536ef7 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 16 Dec 2015 20:41:18 +0000 Subject: Replace MessageError with std::runtime_error. --- src/exceptions.cc | 2 +- src/exceptions.h | 43 +++++++++++++------------------------------ 2 files changed, 14 insertions(+), 31 deletions(-) (limited to 'src/exceptions.cc') diff --git a/src/exceptions.cc b/src/exceptions.cc index f33a1e2..4d9d29f 100644 --- a/src/exceptions.cc +++ b/src/exceptions.cc @@ -24,7 +24,7 @@ using std::string; using namespace sub; ProgrammingError::ProgrammingError (string file, int line) - : MessageError (String::compose ("Programming error at %1:%2", file, line)) + : runtime_error (String::compose ("Programming error at %1:%2", file, line)) { } diff --git a/src/exceptions.h b/src/exceptions.h index 5995942..c6f7f1a 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -25,81 +25,64 @@ namespace sub { -class MessageError : public std::exception -{ -public: - MessageError (std::string const & message) - : _message (message) {} - ~MessageError () throw () {} - - /** @return error message */ - char const * what () const throw () { - return _message.c_str (); - } - -private: - /** error message */ - std::string _message; -}; - /** @class XMLError * @brief An error raised when reading an XML file. */ -class XMLError : public MessageError +class XMLError : public std::runtime_error { public: XMLError (std::string const & message) - : MessageError (message) + : std::runtime_error (message) {} }; /** @class STLError * @brief An error raised when reading a binary STL file. */ -class STLError : public MessageError +class STLError : public std::runtime_error { public: STLError (std::string const & message) - : MessageError (message) + : std::runtime_error (message) {} }; /** @class SubripError * @brief An error raised when reading a Subrip file. */ -class SubripError : public MessageError +class SubripError : public std::runtime_error { public: SubripError (std::string saw, std::string expecting) - : MessageError ("Error in SubRip file: saw " + saw + " while expecting " + expecting) + : std::runtime_error ("Error in SubRip file: saw " + saw + " while expecting " + expecting) {} }; -class MXFError : public MessageError +class MXFError : public std::runtime_error { public: MXFError (std::string const & message) - : MessageError (message) + : std::runtime_error (message) {} }; -class UnknownFrameRateError : public MessageError +class UnknownFrameRateError : public std::runtime_error { public: UnknownFrameRateError () - : MessageError ("unknown frame rate") + : std::runtime_error ("unknown frame rate") {} }; -class DCPError : public MessageError +class DCPError : public std::runtime_error { public: DCPError (std::string const & message) - : MessageError (message) + : std::runtime_error (message) {} }; -class ProgrammingError : public MessageError +class ProgrammingError : public std::runtime_error { public: ProgrammingError (std::string file, int line); -- cgit v1.2.3