diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-02 20:14:00 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-02 20:14:00 +0000 |
commit | 441f938df65b2b42327739cfb8fc19bc6062fdf0 (patch) | |
tree | 910693173d1f878537af4fe6e7f7edde7a71ec30 | |
parent | 2e9c8e2454186b93a6ef11ace4da67d1144e752e (diff) |
Implement destructor, move and copy constructors.
-rw-r--r-- | document/src/vespa/document/base/exceptions.cpp | 27 | ||||
-rw-r--r-- | document/src/vespa/document/base/exceptions.h | 8 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/exception.cpp | 10 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/exception.h | 39 |
4 files changed, 42 insertions, 42 deletions
diff --git a/document/src/vespa/document/base/exceptions.cpp b/document/src/vespa/document/base/exceptions.cpp index eb9b2eff248..b0c2cf05eb1 100644 --- a/document/src/vespa/document/base/exceptions.cpp +++ b/document/src/vespa/document/base/exceptions.cpp @@ -19,19 +19,14 @@ InvalidDataTypeException::InvalidDataTypeException( const DataType& expected, const vespalib::string& location) : vespalib::IllegalStateException( - vespalib::make_string( - "Got %s while expecting %s. These types are not compatible.", - actual.toString().c_str(), - expected.toString().c_str() - ), location, 1), + vespalib::make_string("Got %s while expecting %s. These types are not compatible.", + actual.toString().c_str(), expected.toString().c_str()), location, 1), _actual(actual), _expected(expected) { } -InvalidDataTypeException::~InvalidDataTypeException() throw() -{ -} +InvalidDataTypeException::~InvalidDataTypeException() = default; InvalidDataTypeConversionException::InvalidDataTypeConversionException( const DataType &actual, @@ -48,9 +43,7 @@ InvalidDataTypeConversionException::InvalidDataTypeConversionException( { } -InvalidDataTypeConversionException::~InvalidDataTypeConversionException() throw() -{ -} +InvalidDataTypeConversionException::~InvalidDataTypeConversionException() = default; DocumentTypeNotFoundException::DocumentTypeNotFoundException(const vespalib::string& name, const vespalib::string& location) : Exception("Document type "+name+" not found", location, 1), @@ -71,7 +64,8 @@ DataTypeNotFoundException::DataTypeNotFoundException(const vespalib::string& nam AnnotationTypeNotFoundException::AnnotationTypeNotFoundException( int id, const vespalib::string& location) : Exception(vespalib::make_string("Data type with id %d not found", id), - location, 1) { + location, 1) +{ } FieldNotFoundException:: @@ -96,13 +90,8 @@ FieldNotFoundException(int fieldId, { } -FieldNotFoundException::~FieldNotFoundException() throw() -{ -} - -DocumentTypeNotFoundException::~DocumentTypeNotFoundException() throw() -{ -} +FieldNotFoundException::~FieldNotFoundException() = default; +DocumentTypeNotFoundException::~DocumentTypeNotFoundException() = default; VESPA_IMPLEMENT_EXCEPTION(WrongTensorTypeException, vespalib::Exception); diff --git a/document/src/vespa/document/base/exceptions.h b/document/src/vespa/document/base/exceptions.h index 0b7f8364702..6e91b5c08ee 100644 --- a/document/src/vespa/document/base/exceptions.h +++ b/document/src/vespa/document/base/exceptions.h @@ -4,7 +4,7 @@ #include <memory> #include <vespa/vespalib/util/exceptions.h> -#include <stdint.h> +#include <cstdint> namespace document { @@ -22,7 +22,7 @@ public: InvalidDataTypeException(const DataType &actual, const DataType &wanted, const vespalib::string & location); - virtual ~InvalidDataTypeException() throw(); + virtual ~InvalidDataTypeException(); const DataType& getActualDataType() const { return _actual; } const DataType& getExpectedDataType() const { return _expected; } @@ -75,7 +75,7 @@ private: public: DocumentTypeNotFoundException(const vespalib::string & name, const vespalib::string& location); - virtual ~DocumentTypeNotFoundException() throw(); + ~DocumentTypeNotFoundException() override; const vespalib::string& getDocumentTypeName() const { return _type; } @@ -130,7 +130,7 @@ public: FieldNotFoundException(int32_t fieldId, int16_t serializationVersion, const vespalib::string& location); - ~FieldNotFoundException() throw(); + ~FieldNotFoundException() override; const vespalib::string& getFieldName() const { return _fieldName; } int32_t getFieldId() const { return _fieldId; }; diff --git a/vespalib/src/vespa/vespalib/util/exception.cpp b/vespalib/src/vespa/vespalib/util/exception.cpp index 89011ae04b5..a4fa118616b 100644 --- a/vespalib/src/vespa/vespalib/util/exception.cpp +++ b/vespalib/src/vespa/vespalib/util/exception.cpp @@ -9,7 +9,7 @@ namespace vespalib { ExceptionPtr::ExceptionPtr() - : _ref(NULL) + : _ref(nullptr) { } @@ -19,7 +19,7 @@ ExceptionPtr::ExceptionPtr(const Exception &e) } ExceptionPtr::ExceptionPtr(const ExceptionPtr &rhs) - : _ref(rhs._ref != NULL ? rhs._ref->clone() : NULL) + : _ref(rhs._ref != nullptr ? rhs._ref->clone() : nullptr) { } @@ -79,15 +79,17 @@ Exception::Exception(stringref msg, const Exception &cause, stringref location, Exception::Exception(const Exception &) = default; Exception & Exception::operator = (const Exception &) = default; +Exception::Exception(Exception &&) noexcept = default; +Exception & Exception::operator = (Exception &&) noexcept = default; Exception::~Exception() = default; const char * -Exception::what() const throw() +Exception::what() const noexcept { if (_what.empty()) { _what.append(toString()); for (const Exception *next = getCause(); - next != NULL; next = next->getCause()) + next != nullptr; next = next->getCause()) { _what.append("\n--> Caused by: "); _what.append(next->toString()); diff --git a/vespalib/src/vespa/vespalib/util/exception.h b/vespalib/src/vespa/vespalib/util/exception.h index 7571025b6ef..0acaabdd92c 100644 --- a/vespalib/src/vespa/vespalib/util/exception.h +++ b/vespalib/src/vespa/vespalib/util/exception.h @@ -61,10 +61,15 @@ #define VESPA_DEFINE_EXCEPTION(MyClass, Parent) \ class MyClass : public Parent { \ public: \ - MyClass(vespalib::stringref msg, \ - vespalib::stringref location = "", int skipStack = 0); \ - MyClass(vespalib::stringref msg, const Exception &cause, \ - vespalib::stringref location = "", int skipStack = 0); \ + MyClass(vespalib::stringref msg, \ + vespalib::stringref location = "", int skipStack = 0); \ + MyClass(vespalib::stringref msg, const Exception &cause, \ + vespalib::stringref location = "", int skipStack = 0); \ + MyClass(const MyClass &); \ + MyClass & operator=(const MyClass &) = delete; \ + MyClass(MyClass &&) noexcept; \ + MyClass & operator=(MyClass &&) noexcept; \ + ~MyClass() override; \ VESPA_DEFINE_EXCEPTION_SPINE(MyClass) \ }; @@ -77,12 +82,16 @@ public: \ * @param MyClass the name of your class **/ #define VESPA_IMPLEMENT_EXCEPTION(MyClass, Parent) \ - MyClass::MyClass(vespalib::stringref msg, \ - vespalib::stringref location, int skipStack) \ + MyClass::MyClass(vespalib::stringref msg, \ + vespalib::stringref location, int skipStack) \ : Parent(msg, location, skipStack + 1) {} \ - MyClass::MyClass(vespalib::stringref msg, const Exception &cause, \ - vespalib::stringref location, int skipStack) \ + MyClass::MyClass(vespalib::stringref msg, const Exception &cause, \ + vespalib::stringref location, int skipStack) \ : Parent(msg, cause, location, skipStack + 1) {} \ + MyClass::MyClass(const MyClass &) = default; \ + MyClass::MyClass(MyClass &&) noexcept = default; \ + MyClass & MyClass::operator=(MyClass &&) noexcept = default; \ + MyClass::~MyClass() = default; \ VESPA_IMPLEMENT_EXCEPTION_SPINE(MyClass) namespace vespalib { @@ -126,10 +135,10 @@ public: ~ExceptionPtr(); /** @brief test if this object actually contains an exception */ - bool isSet() const { return (_ref != 0); } + [[nodiscard]] bool isSet() const { return (_ref != nullptr); } /** @brief get pointer to currently held exception, returns NULL if not set */ - const Exception *get() const { return _ref; } + [[nodiscard]] const Exception *get() const { return _ref; } /** @brief use pointer to currently held exception, will crash if not set */ const Exception *operator->() const { return _ref; } @@ -186,7 +195,7 @@ public: * should send (skipStack + 1) to the parent constructor (see * \ref VESPA_DEFINE_EXCEPTION for subclass implementation). **/ - Exception(stringref msg, stringref location = "", int skipStack = 0); + explicit Exception(stringref msg, stringref location = "", int skipStack = 0); /** * @brief Construct an exception with a message, a causing exception, and a source code location. * @param msg A user-readable message describing the problem @@ -202,13 +211,13 @@ public: stringref location = "", int skipStack = 0); Exception(const Exception &); Exception & operator = (const Exception &); - Exception(Exception &&) = default; - Exception & operator = (Exception &&) = default; - virtual ~Exception(); + Exception(Exception &&) noexcept; + Exception & operator = (Exception &&) noexcept; + ~Exception() override; /** @brief Returns a string describing the current exception, including cause if any */ - const char *what() const throw() override; // should not be overridden + const char *what() const noexcept override; // should not be overridden /** @brief Returns a pointer to underlying cause (or NULL if no cause) */ const Exception *getCause() const { return _cause.get(); } |