diff --git a/src/core/exception.cpp b/src/core/exception.cpp index c3f0ace22..107e04260 100644 --- a/src/core/exception.cpp +++ b/src/core/exception.cpp @@ -1,103 +1,105 @@ /* Copyright (c) 2009 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "exceptionbase.h" #include #include using namespace Akonadi; class Exception::Private { public: explicit Private(const QByteArray &what): what(what) {} QByteArray what; QByteArray assembledWhat; }; Exception::Exception(const char *what) { try { d = std::make_unique(what); } catch (...) { } } Exception::Exception(const QByteArray &what) { try { d = std::make_unique(what); } catch (...) { } } Exception::Exception(const QString &what) { try { d = std::make_unique(what.toUtf8()); } catch (...) { } } +Exception::Exception(Exception &&) noexcept = default; + Exception::~Exception() = default; QByteArray Exception::type() const { static constexpr char mytype[] = "Akonadi::Exception"; try { return QByteArray::fromRawData("Akonadi::Exception", sizeof(mytype) - 1); } catch (...) { return QByteArray(); } } const char *Exception::what() const noexcept { static constexpr char fallback[] = ""; if (!d) { return fallback; } if (d->assembledWhat.isEmpty()) { try { d->assembledWhat = QByteArray(type() + ": " + d->what); } catch (...) { return "caught some exception while assembling Akonadi::Exception::what() return value"; } } return d->assembledWhat.constData(); } #define AKONADI_EXCEPTION_IMPLEMENT_TRIVIAL_INSTANCE(classname) \ Akonadi::classname::~classname() = default; \ QByteArray Akonadi::classname::type() const { \ static constexpr char mytype[] = "Akonadi::" #classname ; \ try { \ return QByteArray::fromRawData( mytype, sizeof (mytype)-1 ); \ } catch ( ... ) { \ return QByteArray(); \ } \ } AKONADI_EXCEPTION_IMPLEMENT_TRIVIAL_INSTANCE(PayloadException) #undef AKONADI_EXCEPTION_IMPLEMENT_TRIVIAL_INSTANCE diff --git a/src/core/exceptionbase.h b/src/core/exceptionbase.h index 502ed44e9..87cce749a 100644 --- a/src/core/exceptionbase.h +++ b/src/core/exceptionbase.h @@ -1,103 +1,104 @@ /* Copyright (c) 2009 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_EXCEPTIONBASE_H #define AKONADI_EXCEPTIONBASE_H #include "akonadicore_export.h" #include #include #include class QString; namespace Akonadi { #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable: 4275) // we are exporting a subclass of an unexported class, MSVC complains #endif /** Base class for exceptions used by the Akonadi library. */ class AKONADICORE_EXPORT Exception : public std::exception { public: /** Creates a new exception with the error message @p what. */ explicit Exception(const char *what); /** Creates a new exception with the error message @p what. */ explicit Exception(const QByteArray &what); /** Creates a new exception with the error message @p what. */ explicit Exception(const QString &what); + Exception(Exception &&) noexcept; + /** Destructor. */ ~Exception() override; /** Returns the error message associated with this exception. */ const char *what() const noexcept override; /** Returns the type of this exception. */ virtual QByteArray type() const; // ### Akonadi 2: return const char * private: - Q_DISABLE_COPY_MOVE(Exception) - class Private; std::unique_ptr d; }; #ifdef _MSC_VER #pragma warning(pop) #endif #define AKONADI_EXCEPTION_MAKE_TRIVIAL_INSTANCE(classname) \ class AKONADICORE_EXPORT classname : public Akonadi::Exception \ { \ public: \ explicit classname(const char *what): Akonadi::Exception(what) {} \ explicit classname(const QByteArray &what): Akonadi::Exception(what) {} \ explicit classname(const QString &what): Akonadi::Exception(what) {} \ + classname(classname &&) = default; \ ~classname() override; \ QByteArray type() const override; \ } AKONADI_EXCEPTION_MAKE_TRIVIAL_INSTANCE(PayloadException); #undef AKONADI_EXCEPTION_MAKE_TRIVIAL_INSTANCE } #endif