From 5c32ae58690080424d57c88771388c93da649da7 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Thu, 13 Sep 2012 15:09:02 +0200 Subject: [PATCH] removed boost exceptions --- Makefile.in | 23 +- arangod/RestHandler/BatchJob.h | 4 +- lib/Basics/Exceptions.cpp | 196 ++++++ lib/Basics/Exceptions.h | 721 +++----------------- lib/Basics/FileUtils.cpp | 16 +- lib/Dispatcher/DispatcherThread.cpp | 4 +- lib/GeneralServer/GeneralServer.h | 6 +- lib/GeneralServer/GeneralServerDispatcher.h | 2 +- lib/Makefile.files | 1 + lib/Rest/Url.cpp | 2 +- lib/Variant/VariantMatrix2.cpp | 12 +- 11 files changed, 323 insertions(+), 664 deletions(-) create mode 100644 lib/Basics/Exceptions.cpp diff --git a/Makefile.in b/Makefile.in index 25a7d50b3a..e3c6faf7e4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -342,10 +342,10 @@ am__v_at_0 = @ lib_libarango_a_AR = $(AR) $(ARFLAGS) lib_libarango_a_LIBADD = am__lib_libarango_a_SOURCES_DIST = lib/Basics/ConditionLocker.cpp \ - lib/Basics/ConditionVariable.cpp lib/Basics/FileUtils.cpp \ - lib/Basics/Initialise.cpp lib/Basics/LibraryLoader.cpp \ - lib/Basics/Mutex.cpp lib/Basics/MutexLocker.cpp \ - lib/Basics/ProgramOptions.cpp \ + lib/Basics/ConditionVariable.cpp lib/Basics/Exceptions.cpp \ + lib/Basics/FileUtils.cpp lib/Basics/Initialise.cpp \ + lib/Basics/LibraryLoader.cpp lib/Basics/Mutex.cpp \ + lib/Basics/MutexLocker.cpp lib/Basics/ProgramOptions.cpp \ lib/Basics/ProgramOptionsDescription.cpp lib/Basics/Random.cpp \ lib/Basics/ReadLocker.cpp lib/Basics/ReadUnlocker.cpp \ lib/Basics/ReadWriteLock.cpp lib/Basics/StringUtils.cpp \ @@ -401,7 +401,8 @@ am__dirstamp = $(am__leading_dot)dirstamp @ENABLE_ZEROMQ_TRUE@ lib/ZeroMQ/ZeroMQWorkerThread.$(OBJEXT) am_lib_libarango_a_OBJECTS = lib/Basics/ConditionLocker.$(OBJEXT) \ lib/Basics/ConditionVariable.$(OBJEXT) \ - lib/Basics/FileUtils.$(OBJEXT) lib/Basics/Initialise.$(OBJEXT) \ + lib/Basics/Exceptions.$(OBJEXT) lib/Basics/FileUtils.$(OBJEXT) \ + lib/Basics/Initialise.$(OBJEXT) \ lib/Basics/LibraryLoader.$(OBJEXT) lib/Basics/Mutex.$(OBJEXT) \ lib/Basics/MutexLocker.$(OBJEXT) \ lib/Basics/ProgramOptions.$(OBJEXT) \ @@ -1276,10 +1277,10 @@ WIKI = \ jsUnity lib_libarango_a_SOURCES = lib/Basics/ConditionLocker.cpp \ - lib/Basics/ConditionVariable.cpp lib/Basics/FileUtils.cpp \ - lib/Basics/Initialise.cpp lib/Basics/LibraryLoader.cpp \ - lib/Basics/Mutex.cpp lib/Basics/MutexLocker.cpp \ - lib/Basics/ProgramOptions.cpp \ + lib/Basics/ConditionVariable.cpp lib/Basics/Exceptions.cpp \ + lib/Basics/FileUtils.cpp lib/Basics/Initialise.cpp \ + lib/Basics/LibraryLoader.cpp lib/Basics/Mutex.cpp \ + lib/Basics/MutexLocker.cpp lib/Basics/ProgramOptions.cpp \ lib/Basics/ProgramOptionsDescription.cpp lib/Basics/Random.cpp \ lib/Basics/ReadLocker.cpp lib/Basics/ReadUnlocker.cpp \ lib/Basics/ReadWriteLock.cpp lib/Basics/StringUtils.cpp \ @@ -1796,6 +1797,8 @@ lib/Basics/ConditionLocker.$(OBJEXT): lib/Basics/$(am__dirstamp) \ lib/Basics/$(DEPDIR)/$(am__dirstamp) lib/Basics/ConditionVariable.$(OBJEXT): lib/Basics/$(am__dirstamp) \ lib/Basics/$(DEPDIR)/$(am__dirstamp) +lib/Basics/Exceptions.$(OBJEXT): lib/Basics/$(am__dirstamp) \ + lib/Basics/$(DEPDIR)/$(am__dirstamp) lib/Basics/FileUtils.$(OBJEXT): lib/Basics/$(am__dirstamp) \ lib/Basics/$(DEPDIR)/$(am__dirstamp) lib/Basics/Initialise.$(OBJEXT): lib/Basics/$(am__dirstamp) \ @@ -2912,6 +2915,7 @@ mostlyclean-compile: -rm -f lib/ApplicationServer/ApplicationServer.$(OBJEXT) -rm -f lib/Basics/ConditionLocker.$(OBJEXT) -rm -f lib/Basics/ConditionVariable.$(OBJEXT) + -rm -f lib/Basics/Exceptions.$(OBJEXT) -rm -f lib/Basics/FileUtils.$(OBJEXT) -rm -f lib/Basics/Initialise.$(OBJEXT) -rm -f lib/Basics/LibraryLoader.$(OBJEXT) @@ -3167,6 +3171,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@lib/ApplicationServer/$(DEPDIR)/ApplicationServer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@lib/Basics/$(DEPDIR)/ConditionLocker.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@lib/Basics/$(DEPDIR)/ConditionVariable.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@lib/Basics/$(DEPDIR)/Exceptions.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@lib/Basics/$(DEPDIR)/FileUtils.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@lib/Basics/$(DEPDIR)/Initialise.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@lib/Basics/$(DEPDIR)/LibraryLoader.Po@am__quote@ diff --git a/arangod/RestHandler/BatchJob.h b/arangod/RestHandler/BatchJob.h index b1b8f6068d..ee20c91a29 100644 --- a/arangod/RestHandler/BatchJob.h +++ b/arangod/RestHandler/BatchJob.h @@ -140,12 +140,12 @@ namespace triagens { handler->handleError(ex); } catch (std::exception const& ex) { - triagens::basics::InternalError err(ex); + triagens::basics::InternalError err(ex, __FILE__, __LINE__); handler->handleError(err); } catch (...) { - triagens::basics::InternalError err; + triagens::basics::InternalError err("executeDirectHandler", __FILE__, __LINE__); handler->handleError(err); } } diff --git a/lib/Basics/Exceptions.cpp b/lib/Basics/Exceptions.cpp new file mode 100644 index 0000000000..b0925d431e --- /dev/null +++ b/lib/Basics/Exceptions.cpp @@ -0,0 +1,196 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief basic exceptions +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2004-2012 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Dr. Frank Celler +/// @author Copyright 2009-2012, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#include "Exceptions.h" + +using namespace std; +using namespace triagens::basics; + +// ----------------------------------------------------------------------------- +// --SECTION-- public types +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @addtogroup Utilities +/// @{ +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// @brief base class for all errors +//////////////////////////////////////////////////////////////////////////////// + +TriagensError::TriagensError (string const& type, string const& details, char const* file, int line) + : _type("unknown"), + _details(details), + _file(file), + _line(line) { + _message = "exception in '" + _file + "' at line " + StringUtils::itoa(_line) + ": " + + "type = '" + _type + "'"; + + if (! details.empty()) { + _message += " details = '" + _details + "'"; + } +} + + + +TriagensError::~TriagensError () throw () { +} + + + +char const * TriagensError::what () const throw() { + return _message.c_str(); +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief exception for internal errors +//////////////////////////////////////////////////////////////////////////////// + +InternalError::InternalError (string const& details, char const* file, int line) + : TriagensError("internal error", details, file, line) { +} + + + +InternalError::InternalError (std::exception const& ex, char const* file, int line) + : TriagensError("internal exception", ex.what(), file, line) { +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief exception for out-of-memory errors +//////////////////////////////////////////////////////////////////////////////// + +OutOfMemoryError::OutOfMemoryError (char const* file, int line) + : TriagensError("out-of-memory", "", file, line) { +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief exception for file errors +//////////////////////////////////////////////////////////////////////////////// + +FileError::FileError (string const& func, + string const& details, + string const& filename, + string const& mode, + int error, + char const* file, + int line) + : TriagensError("file-error", details, file, line), + _filename(filename), + _mode(mode), + _error(error) { + if (! mode.empty()) { + _message += " mode = '" + _mode + "'"; + } + + if (_error != 0) { + _message += " errno = " + StringUtils::itoa(_error) + "" + + " error = '" + strerror(_error) + "'"; + } + + if (! _filename.empty()) { + _message += " file = '" + _filename + "'"; + } +} + + + +FileError::~FileError () throw () { +} + + + +void FileError::setFilename (string const& filename) { + _filename = filename; + + if (! _filename.empty()) { + _message += " file = '" + _filename + "'"; + } +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief exception for parse errors +//////////////////////////////////////////////////////////////////////////////// + +ParseError::ParseError (string const& details, + int lineNumber, + char const* file, + int line) + : TriagensError("parse-error", details, file, line), + _lineNumber(lineNumber) { + if (_lineNumber != -1) { + _message += " line-number = '" + StringUtils::itoa(_lineNumber) + "'"; + } +} + + + +void ParseError::setLineNumber (int lineNumber) { + _lineNumber = lineNumber; + + if (_lineNumber != -1) { + _message += " line-number = '" + StringUtils::itoa(_lineNumber) + "'"; + } +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief exception for parameter errors +//////////////////////////////////////////////////////////////////////////////// + +ParameterError::ParameterError (string const& parameter, + string const& details, + string const& func, + char const* file, + int line) + : TriagensError("parameter-error", details, file, line), + _parameter(parameter), + _func(func) { + _message += " parameter = '" + _parameter + "'"; + + if (! _func.empty()) { + _message += " func = '" + _func + "'"; + } +} + + + +ParameterError::~ParameterError () throw () { +} + +//////////////////////////////////////////////////////////////////////////////// +/// @} +//////////////////////////////////////////////////////////////////////////////// + +// ----------------------------------------------------------------------------- +// --SECTION-- END-OF-FILE +// ----------------------------------------------------------------------------- + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" +// End: diff --git a/lib/Basics/Exceptions.h b/lib/Basics/Exceptions.h index 0040d2a4b5..07849902bc 100644 --- a/lib/Basics/Exceptions.h +++ b/lib/Basics/Exceptions.h @@ -32,49 +32,7 @@ #include -#if BOOST_VERSION < 103600 -#undef USE_BOOST_EXCEPTIONS -#else -#define USE_BOOST_EXCEPTIONS 1 -#endif - -#ifdef USE_BOOST_EXCEPTIONS - -#if BOOST_VERSION < 104000 -#include -#else -#include -#endif -#include - -#else #include "Basics/StringUtils.h" -#endif - -// ----------------------------------------------------------------------------- -// --SECTION-- boost -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup Utilities -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -#if defined(USE_BOOST_EXCEPTIONS) && (BOOST_VERSION < 104000) - -namespace boost { - typedef error_info errinfo_api_function; - typedef error_info errinfo_at_line; - typedef error_info errinfo_errno; - typedef error_info errinfo_file_name; - typedef error_info errinfo_file_open_mode; -} - -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- public macros @@ -89,347 +47,91 @@ namespace boost { /// @brief diagnostic output //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - #define DIAGNOSTIC_INFORMATION(e) \ - boost::diagnostic_information(e) - -#else - -#define DIAGNOSTIC_INFORMATION(e) \ - e.diagnostic_information() - -#endif + e.what() //////////////////////////////////////////////////////////////////////////////// /// @brief throws an unqualified exception -/// -/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns. //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - -#define THROW_TRIAGENS_ERROR(mesg, details) \ - do { \ - BOOST_THROW_EXCEPTION(triagens::basics::TriagensError() \ - << triagens::ErrorMessage(mesg) \ - << triagens::ErrorDetails(details)); \ - throw "this cannot happen"; \ - } \ - while (0) - -#else - -#define THROW_TRIAGENS_ERROR(mesg, details) \ - throw triagens::basics::TriagensError(mesg, details) - -#endif +#define THROW_TRIAGENS_ERROR(type, details) \ + throw triagens::basics::TriagensError(type, details, __FILE__, __LINE__) //////////////////////////////////////////////////////////////////////////////// /// @brief throws an exception for internal errors -/// -/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns. //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - -#define THROW_INTERNAL_ERROR(a) \ - do { \ - BOOST_THROW_EXCEPTION(triagens::basics::InternalError() \ - << triagens::ErrorMessage(a) \ - << boost::errinfo_at_line(__LINE__) \ - << boost::errinfo_file_name(__FILE__)); \ - throw "this cannot happen"; \ - } \ - while (0) - -#else - -#define THROW_INTERNAL_ERROR(a) \ - throw triagens::basics::InternalError(a) - -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// @brief throws an exception for internal errors with line info -/// -/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns. -//////////////////////////////////////////////////////////////////////////////// - -#ifdef USE_BOOST_EXCEPTIONS - -#define THROW_INTERNAL_ERROR_L(a, file, line) \ - do { \ - BOOST_THROW_EXCEPTION(triagens::basics::InternalError() \ - << triagens::ErrorMessage(a) \ - << boost::errinfo_at_line(line) \ - << boost::errinfo_file_name(file)); \ - throw "this cannot happen"; \ - } \ - while (0) - -#else - -#define THROW_INTERNAL_ERROR_L(a, file, line) \ - throw triagens::basics::InternalError(a) - -#endif +#define THROW_INTERNAL_ERROR(details) \ + throw triagens::basics::InternalError(details, __FILE__, __LINE__) //////////////////////////////////////////////////////////////////////////////// /// @brief throws an exception for out-of-memory errors -/// -/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns. //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - -#define THROW_OUT_OF_MEMORY_ERROR() \ - do { \ - BOOST_THROW_EXCEPTION(triagens::basics::OutOfMemoryError()); \ - throw "this cannot happen"; \ - } \ - while (0) - -#else - -#define THROW_OUT_OF_MEMORY_ERROR() \ - throw triagens::basics::OutOfMemoryError() - -#endif +#define THROW_OUT_OF_MEMORY_ERROR() \ + throw triagens::basics::OutOfMemoryError(__FILE__, __LINE__) //////////////////////////////////////////////////////////////////////////////// /// @brief throws an exception for file open errors -/// -/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns. //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - -#define THROW_FILE_OPEN_ERROR(func, file, mode) \ - do { \ - BOOST_THROW_EXCEPTION(triagens::basics::FileError() \ - << triagens::ErrorMessage("file open error") \ - << boost::errinfo_api_function(func) \ - << boost::errinfo_errno(errno) \ - << boost::errinfo_file_name(file) \ - << boost::errinfo_file_open_mode(mode)); \ - throw "this cannot happen"; \ - } \ - while (0) - -#else - -#define THROW_FILE_OPEN_ERROR(func, file, mode) \ - throw triagens::basics::FileError("file open error", file) - -#endif +#define THROW_FILE_OPEN_ERROR(func, file, mode, error) \ + throw triagens::basics::FileError(func, "file open error", file, mode, error, __FILE__, __LINE__) //////////////////////////////////////////////////////////////////////////////// /// @brief throws an exception for file errors -/// -/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns. //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - -#define THROW_FILE_FUNC_ERROR(func, mesg) \ - do { \ - BOOST_THROW_EXCEPTION(triagens::basics::FileError() \ - << triagens::ErrorMessage(mesg) \ - << boost::errinfo_api_function(func) \ - << boost::errinfo_errno(errno)); \ - throw "this cannot happen"; \ - } \ - while (0) - -#else - -#define THROW_FILE_FUNC_ERROR(func, mesg) \ - throw triagens::basics::FileError(func, mesg) - -#endif +#define THROW_FILE_FUNC_ERROR(func, details, error) \ + throw triagens::basics::FileError(func, details, "", "", error, __FILE__, __LINE__) //////////////////////////////////////////////////////////////////////////////// /// @brief throws an exception for file errors -/// -/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns. //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - -#define THROW_FILE_FUNC_ERROR_E(func, mesg, error) \ - do { \ - BOOST_THROW_EXCEPTION(triagens::basics::FileError() \ - << triagens::ErrorMessage(mesg) \ - << boost::errinfo_api_function(func) \ - << boost::errinfo_errno(error)); \ - throw "this cannot happen"; \ - } \ - while (0) - -#else - -#define THROW_FILE_FUNC_ERROR_E(func, mesg, error) \ - throw triagens::basics::FileError(func, mesg + (" " + triagens::basics::StringUtils::itoa(error))) - -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// @brief throws an exception for file errors -/// -/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns. -//////////////////////////////////////////////////////////////////////////////// - -#ifdef USE_BOOST_EXCEPTIONS - -#define THROW_FILE_ERROR(mesg) \ - do { \ - BOOST_THROW_EXCEPTION(triagens::basics::FileError() \ - << triagens::ErrorMessage(mesg)); \ - throw "this cannot happen"; \ - } \ - while (0) - -#else - -#define THROW_FILE_ERROR(mesg) \ - throw triagens::basics::FileError(mesg) - -#endif +#define THROW_FILE_ERROR(details, error) \ + throw triagens::basics::FileError("", details, "", "", error, __FILE__, __LINE__) //////////////////////////////////////////////////////////////////////////////// /// @brief rethrows an exception with filename //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - -#define RETHROW_FILE_NAME(ex, file) \ - do { \ - ex << boost::errinfo_file_name(file); \ - throw ex; \ - } while (0) - -#else - -#define RETHROW_FILE_NAME(ex, file) \ - throw ex - -#endif +#define RETHROW_FILE_NAME(ex, file) \ + do { \ + ex.setFilename(file); \ + throw ex; \ + } while (0) //////////////////////////////////////////////////////////////////////////////// /// @brief throws an exception for parse errors -/// -/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns. //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - -#define THROW_PARSE_ERROR(mesg) \ - do { \ - BOOST_THROW_EXCEPTION(triagens::basics::ParseError() \ - << triagens::ErrorMessage(mesg)); \ - throw "this cannot happen"; \ - } \ - while (0) - -#else - -#define THROW_PARSE_ERROR(mesg) \ - throw triagens::basics::ParseError(mesg) - -#endif +#define THROW_PARSE_ERROR(details) \ + throw triagens::basics::ParseError(details, -1, __FILE__, __LINE__) //////////////////////////////////////////////////////////////////////////////// /// @brief throws an exception for parse errors -/// -/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns. //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - -#define THROW_PARSE_ERROR_L(line, mesg) \ - do { \ - BOOST_THROW_EXCEPTION(triagens::basics::ParseError() \ - << triagens::ErrorMessage(mesg) \ - << boost::errinfo_at_line(line)); \ - throw "this cannot happen"; \ - } \ - while (0) - -#else - -#define THROW_PARSE_ERROR_L(line, mesg) \ - throw triagens::basics::ParseError(mesg, "line " + triagens::basics::StringUtils::itoa(line)) - -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// @brief throws an exception for parse errors -/// -/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns. -//////////////////////////////////////////////////////////////////////////////// - -#ifdef USE_BOOST_EXCEPTIONS - -#define THROW_PARSE_ERROR_D(mesg, details) \ - do { \ - BOOST_THROW_EXCEPTION(triagens::basics::ParseError() \ - << triagens::ErrorMessage(mesg) \ - << triagens::ErrorDetails(details)); \ - throw "this cannot happen"; \ - } \ - while (0) - -#else - -#define THROW_PARSE_ERROR_D(mesg, details) \ - throw triagens::basics::ParseError(mesg, details) - -#endif +#define THROW_PARSE_ERROR_L(details, line) \ + throw triagens::basics::ParseError(details, line, __FILE__, __LINE__) //////////////////////////////////////////////////////////////////////////////// /// @brief rethrows an exception with line //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - -#define RETHROW_LINE(ex, line) \ - do { \ - ex << boost::errinfo_at_line(line); \ - throw ex; \ - } while (0) - -#else - -#define RETHROW_LINE(ex, line) \ - throw ex - -#endif +#define RETHROW_LINE(ex, line) \ + do { \ + ex.setLineNumber(line); \ + throw ex; \ + } while (0) //////////////////////////////////////////////////////////////////////////////// /// @brief throws an exception for parameter errors -/// -/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns. //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - -#define THROW_PARAMETER_ERROR(param, func, mesg) \ - do { \ - BOOST_THROW_EXCEPTION(triagens::basics::ParameterError() \ - << triagens::ErrorMessage(mesg) \ - << ErrorParameterName(param) \ - << boost::errinfo_api_function(func)); \ - throw "this cannot happen"; \ - } \ - while (0) - -#else - -#define THROW_PARAMETER_ERROR(param, func, mesg) \ - throw triagens::basics::ParameterError(mesg, param + string(" in ") + func) - -#endif +#define THROW_PARAMETER_ERROR(parameter, details, func) \ + throw triagens::basics::ParameterError(parameter, details, func, __FILE__, __LINE__) //////////////////////////////////////////////////////////////////////////////// /// @} @@ -439,377 +141,132 @@ namespace boost { // --SECTION-- public types // ----------------------------------------------------------------------------- -namespace triagens { - //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Utilities /// @{ //////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -/// @brief message info -//////////////////////////////////////////////////////////////////////////////// - -#ifdef USE_BOOST_EXCEPTIONS - typedef boost::error_info ErrorMessage; -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// @brief message details -//////////////////////////////////////////////////////////////////////////////// - -#ifdef USE_BOOST_EXCEPTIONS - typedef boost::error_info ErrorDetails; -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// @brief parameter name -//////////////////////////////////////////////////////////////////////////////// - -#ifdef USE_BOOST_EXCEPTIONS - typedef boost::error_info ErrorParameterName; -#endif - +namespace triagens { namespace basics { //////////////////////////////////////////////////////////////////////////////// /// @brief base class for all errors //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - - class TriagensError : public virtual std::exception, public virtual boost::exception { - public: - ~TriagensError () throw() { - } - - public: - char const * what () const throw() { - return "triagens error"; - } - - string description () const { - return boost::diagnostic_information(*this); - } - }; - -#else - class TriagensError : public virtual std::exception { public: - TriagensError () - : message("unknown") { - } + TriagensError (string const& type, + string const& details, + char const* file, + int line); - TriagensError (string mesg) - : message(mesg) { - } - - TriagensError (string mesg, string details) - : message(mesg + " (" + details + ")") { - } - - ~TriagensError () throw() { - } + ~TriagensError () throw (); public: - string diagnostic_information () const { - return string(what()) + ": " + message; - } + char const * what () const throw(); - string description () const { - return diagnostic_information(); - } - - char const * what () const throw() { - return "triagens error"; - } - - string const& details () const throw() { - return message; - } - - private: - string const message; + protected: + string _message; + string _type; + string _details; + string _file; + int _line; }; -#endif - //////////////////////////////////////////////////////////////////////////////// /// @brief exception for internal errors //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - - struct InternalError : public TriagensError { + class InternalError : public TriagensError { public: - InternalError () { - } - - InternalError (string const& what) { - *this << ErrorMessage(what); - } - - InternalError (std::exception const& ex) { - *this << ErrorMessage(ex.what()); - } - - public: - char const * what () const throw() { - return "internal error"; - } + InternalError (string const& details, char const* file, int line); + InternalError (std::exception const& ex, char const* file, int line); }; -#else - - struct InternalError : public TriagensError { - public: - InternalError () : TriagensError("internal error") { - } - - InternalError (string mesg) : TriagensError(mesg) { - } - - InternalError (std::exception const& ex) : TriagensError(ex.what()) { - } - - public: - char const * what () const throw() { - return "internal error"; - } - }; - -#endif - //////////////////////////////////////////////////////////////////////////////// /// @brief exception for out-of-memory errors //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - - struct OutOfMemoryError : public TriagensError { + class OutOfMemoryError : public TriagensError { public: - char const * what () const throw() { - return "out-of-memory error"; - } + OutOfMemoryError (char const* file, int line); }; -#else - - struct OutOfMemoryError : public TriagensError { - public: - OutOfMemoryError () : TriagensError("out-of-memory") { - } - - public: - char const * what () const throw() { - return "out-of-memory error"; - } - }; - -#endif - //////////////////////////////////////////////////////////////////////////////// /// @brief exception for file errors //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - - struct FileError : public TriagensError { + class FileError : public TriagensError { public: - char const * what () const throw() { - return "file error"; - } + FileError (string const& func, + string const& details, + string const& filename, + string const& mode, + int error, + char const* file, + int line); + + ~FileError () throw (); + + public: + void setFilename (string const&); + + protected: + string _func; + string _filename; + string _mode; + int _error; }; -#else - - struct FileError : public TriagensError { - public: - FileError () : TriagensError("file error") { - } - - FileError (string mesg) : TriagensError(mesg) { - } - - FileError (string mesg, string details) : TriagensError(mesg, details) { - } - - public: - char const * what () const throw() { - return "file error"; - } - }; - -#endif - //////////////////////////////////////////////////////////////////////////////// /// @brief exception for parse errors //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - struct ParseError : public TriagensError { public: - char const * what () const throw() { - return "parse error"; - } - }; - -#else - - struct ParseError : public TriagensError { - public: - ParseError () : TriagensError("parse error") { - } - - ParseError (string mesg) : TriagensError(mesg) { - } - - ParseError (string mesg, string details) : TriagensError(mesg, details) { - } + ParseError (string const& details, + int lineNumber, + char const* file, + int line); public: - char const * what () const throw() { - return "parse error"; - } - }; + void setLineNumber (int); -#endif + protected: + int _lineNumber; + }; //////////////////////////////////////////////////////////////////////////////// /// @brief exception for parameter errors //////////////////////////////////////////////////////////////////////////////// -#ifdef USE_BOOST_EXCEPTIONS - struct ParameterError : public TriagensError { public: - char const * what () const throw() { - return "parameter error"; - } + ParameterError (string const& parameter, + string const& details, + string const& func, + char const* file, + int line); + + ~ParameterError () throw (); + + protected: + string _parameter; + string _func; }; - -#else - - struct ParameterError : public TriagensError { - public: - ParameterError () : TriagensError("parameter error") { - } - - ParameterError (string mesg) : TriagensError(mesg) { - } - - ParameterError (string mesg, string details) : TriagensError(mesg, details) { - } - - public: - char const * what () const throw() { - return "parameter error"; - } - }; - -#endif - } } -// ----------------------------------------------------------------------------- -// --SECTION-- boost -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup Utilities -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -#ifdef USE_BOOST_EXCEPTIONS - -/// @cond IGNORE - -namespace boost { - -#if BOOST_VERSION < 104300 -#define TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE char const * -#else -#define TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE std::string -#endif - - template<> - inline - TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE - boost::error_info::tag_typeid_name () const { - return "message"; - } - - - - template<> - inline - TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE - boost::error_info::tag_typeid_name () const { - return "details"; - } - - - - template<> - inline - TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE - boost::errinfo_errno::tag_typeid_name () const { - return "errno"; - } - - - - template<> - inline - TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE - boost::errinfo_file_name::tag_typeid_name () const { - return "file name"; - } - - - - template<> - inline - TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE - boost::errinfo_file_open_mode::tag_typeid_name () const { - return "file open mode"; - } - - - - template<> - inline - TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE - boost::errinfo_api_function::tag_typeid_name () const { - return "api function"; - } - - - - template<> - inline - TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE - boost::errinfo_at_line::tag_typeid_name () const { - return "at line"; - } - -#undef TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE - -} - -/// @endcond - -#endif - //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// #endif +// ----------------------------------------------------------------------------- +// --SECTION-- END-OF-FILE +// ----------------------------------------------------------------------------- + // Local Variables: // mode: outline-minor // outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" diff --git a/lib/Basics/FileUtils.cpp b/lib/Basics/FileUtils.cpp index c5116a7618..5cce2a4132 100644 --- a/lib/Basics/FileUtils.cpp +++ b/lib/Basics/FileUtils.cpp @@ -78,7 +78,7 @@ namespace triagens { int fd = TRI_OPEN(filename.c_str(), O_RDONLY); if (fd == -1) { - THROW_FILE_OPEN_ERROR("open", filename, "O_RDONLY"); + THROW_FILE_OPEN_ERROR("open", filename, "O_RDONLY", errno); } char buffer[10240]; @@ -95,7 +95,7 @@ namespace triagens { TRI_CLOSE(fd); LOGGER_TRACE << "read failed for '" << filename << "' with " << strerror(errno) << " and result " << n << " on fd " << fd; - THROW_FILE_FUNC_ERROR("read", strerror(errno)); + THROW_FILE_FUNC_ERROR("read", "", errno); } result.appendText(buffer, n); @@ -114,7 +114,7 @@ namespace triagens { int fd = TRI_OPEN(filename.c_str(), O_RDONLY); if (fd == -1) { - THROW_FILE_OPEN_ERROR("open", filename, "O_RDONLY"); + THROW_FILE_OPEN_ERROR("open", filename, "O_RDONLY", errno); } char buffer[10240]; @@ -130,7 +130,7 @@ namespace triagens { TRI_CLOSE(fd); LOGGER_TRACE << "read failed for '" << filename << "' with " << strerror(errno) << " and result " << n << " on fd " << fd; - THROW_FILE_FUNC_ERROR("read", strerror(errno)); + THROW_FILE_FUNC_ERROR("read", "", errno); } result.appendText(buffer, n); @@ -146,7 +146,7 @@ namespace triagens { if (fd == -1) { LOGGER_TRACE << "open failed for '" << filename << "' with " << strerror(errno); - THROW_FILE_OPEN_ERROR("open", filename, "O_RDONLY | O_CREAT | O_TRUNC"); + THROW_FILE_OPEN_ERROR("open", filename, "O_RDONLY | O_CREAT | O_TRUNC", errno); } char const* ptr = content.c_str(); @@ -159,7 +159,7 @@ namespace triagens { TRI_CLOSE(fd); LOGGER_TRACE << "write failed for '" << filename << "' with " << strerror(errno) << " and result " << n << " on fd " << fd; - THROW_FILE_FUNC_ERROR("write", strerror(errno)); + THROW_FILE_FUNC_ERROR("write", "", errno); } ptr += n; @@ -177,7 +177,7 @@ namespace triagens { if (fd == -1) { LOGGER_TRACE << "open failed for '" << filename << "' with " << strerror(errno); - THROW_FILE_OPEN_ERROR("open", filename, "O_WRONLY | O_CREAT | O_TRUNC"); + THROW_FILE_OPEN_ERROR("open", filename, "O_WRONLY | O_CREAT | O_TRUNC", errno); } char const* ptr = content.c_str(); @@ -190,7 +190,7 @@ namespace triagens { TRI_CLOSE(fd); LOGGER_TRACE << "write failed for '" << filename << "' with " << strerror(errno) << " and result " << n << " on fd " << fd; - THROW_FILE_FUNC_ERROR("write", strerror(errno)); + THROW_FILE_FUNC_ERROR("write", "", errno); } ptr += n; diff --git a/lib/Dispatcher/DispatcherThread.cpp b/lib/Dispatcher/DispatcherThread.cpp index 53b1a38761..c609672d2e 100644 --- a/lib/Dispatcher/DispatcherThread.cpp +++ b/lib/Dispatcher/DispatcherThread.cpp @@ -152,7 +152,7 @@ void DispatcherThread::run () { } catch (std::exception const& ex) { try { - InternalError err(string("job failed with unknown in work: ") + ex.what()); + InternalError err(string("job failed with unknown in work: ") + ex.what(), __FILE__, __LINE__); job->handleError(err); } @@ -177,7 +177,7 @@ void DispatcherThread::run () { #endif try { - InternalError err("job failed with unknown error in work"); + InternalError err("job failed with unknown error in work", __FILE__, __LINE__); job->handleError(err); } diff --git a/lib/GeneralServer/GeneralServer.h b/lib/GeneralServer/GeneralServer.h index ef4948372c..252a795bcc 100644 --- a/lib/GeneralServer/GeneralServer.h +++ b/lib/GeneralServer/GeneralServer.h @@ -435,13 +435,13 @@ namespace triagens { catch (std::exception const& ex) { RequestStatisticsAgentSetExecuteError(handler); - basics::InternalError err(ex); + basics::InternalError err(ex, __FILE__, __LINE__); handler->handleError(err); } catch (...) { RequestStatisticsAgentSetExecuteError(handler); - basics::InternalError err; + basics::InternalError err("handleRequestDirectly", __FILE__, __LINE__); handler->handleError(err); } @@ -453,7 +453,7 @@ namespace triagens { typename HF::GeneralResponse * response = handler->getResponse(); if (response == 0) { - basics::InternalError err("no response received from handler"); + basics::InternalError err("no response received from handler", __FILE__, __LINE__); handler->handleError(err); response = handler->getResponse(); diff --git a/lib/GeneralServer/GeneralServerDispatcher.h b/lib/GeneralServer/GeneralServerDispatcher.h index 286e3b605b..ac62cdb01a 100644 --- a/lib/GeneralServer/GeneralServerDispatcher.h +++ b/lib/GeneralServer/GeneralServerDispatcher.h @@ -176,7 +176,7 @@ namespace triagens { typename HF::GeneralResponse * response = handler->getResponse(); if (response == 0) { - basics::InternalError err("no response received from handler"); + basics::InternalError err("no response received from handler", __FILE__, __LINE__); handler->handleError(err); response = handler->getResponse(); diff --git a/lib/Makefile.files b/lib/Makefile.files index f87d514bd2..86e0048e3f 100644 --- a/lib/Makefile.files +++ b/lib/Makefile.files @@ -11,6 +11,7 @@ lib_libarango_a_SOURCES = \ lib/Basics/ConditionLocker.cpp \ lib/Basics/ConditionVariable.cpp \ + lib/Basics/Exceptions.cpp \ lib/Basics/FileUtils.cpp \ lib/Basics/Initialise.cpp \ lib/Basics/LibraryLoader.cpp \ diff --git a/lib/Rest/Url.cpp b/lib/Rest/Url.cpp index 52ea4dddca..58da285f8b 100644 --- a/lib/Rest/Url.cpp +++ b/lib/Rest/Url.cpp @@ -97,7 +97,7 @@ Url::Url (string const& urlName) } } else { - THROW_PARAMETER_ERROR("url", "constructor", "url not valid"); + THROW_PARAMETER_ERROR("url", "url not valid", "constructor"); } } diff --git a/lib/Variant/VariantMatrix2.cpp b/lib/Variant/VariantMatrix2.cpp index f80681dccb..278f851753 100644 --- a/lib/Variant/VariantMatrix2.cpp +++ b/lib/Variant/VariantMatrix2.cpp @@ -142,7 +142,7 @@ void VariantMatrix2::print (StringBuffer& buffer, size_t) const { vector const& VariantMatrix2::getDimension (size_t n) const { if (n >= 2) { - THROW_PARAMETER_ERROR("n", "getDimension", "too large"); + THROW_PARAMETER_ERROR("n", "too large", "getDimension"); } return _dimensions[n]; @@ -162,11 +162,11 @@ vector< vector > const& VariantMatrix2::getValues () const { VariantObject* VariantMatrix2::getValue (size_t x, size_t y) const { if (_dimensions[0].size() <= x) { - THROW_PARAMETER_ERROR("x", "setValue", "too large"); + THROW_PARAMETER_ERROR("x", "too large", "setValue"); } if (_dimensions[1].size() <= y) { - THROW_PARAMETER_ERROR("y", "setValue", "too large"); + THROW_PARAMETER_ERROR("y", "too large", "setValue"); } if (_values.size() <= x) { @@ -188,11 +188,11 @@ VariantObject* VariantMatrix2::getValue (size_t x, size_t y) const { void VariantMatrix2::setValue (size_t x, size_t y, VariantObject* object) { if (_dimensions[0].size() <= x) { - THROW_PARAMETER_ERROR("x", "setValue", "too large"); + THROW_PARAMETER_ERROR("x", "too large", "setValue"); } if (_dimensions[1].size() <= y) { - THROW_PARAMETER_ERROR("y", "setValue", "too large"); + THROW_PARAMETER_ERROR("y", "too large", "setValue"); } if (_values.size() <= x) { @@ -218,7 +218,7 @@ void VariantMatrix2::setValue (size_t x, size_t y, VariantObject* object) { size_t VariantMatrix2::addDimension (size_t n, string const& name) { if (n >= 2) { - THROW_PARAMETER_ERROR("n", "addDimension", "too large"); + THROW_PARAMETER_ERROR("n", "too large", "addDimension"); } _dimensions[n].push_back(name);