Verified Commit f1a31ca9 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Remove the deprecated dynamic exception specifier

parent d6cea44a
......@@ -28,65 +28,53 @@ using namespace Akonadi;
class Exception::Private
{
public:
explicit Private(const QByteArray &what): what(what) {}
QByteArray what;
QByteArray assembledWhat;
};
Exception::Exception(const char *what) throw()
: d(nullptr)
Exception::Exception(const char *what)
{
try {
std::unique_ptr<Private> nd(new Private);
nd->what = what;
d = nd.release();
d = std::make_unique<Private>(what);
} catch (...) {
}
}
Exception::Exception(const QByteArray &what) throw()
: d(nullptr)
Exception::Exception(const QByteArray &what)
{
try {
std::unique_ptr<Private> nd(new Private);
nd->what = what;
d = nd.release();
d = std::make_unique<Private>(what);
} catch (...) {
}
}
Exception::Exception(const QString &what) throw()
: d(nullptr)
Exception::Exception(const QString &what)
{
try {
std::unique_ptr<Private> nd(new Private);
nd->what = what.toUtf8();
d = nd.release();
d = std::make_unique<Private>(what.toUtf8());
} catch (...) {
}
}
Exception::Exception(const Akonadi::Exception &other) throw()
Exception::Exception(const Akonadi::Exception &other)
: std::exception(other)
, d(nullptr)
{
if (!other.d) {
return;
}
try {
std::unique_ptr<Private> nd(new Private(*other.d));
d = nd.release();
d = std::make_unique<Private>(*other.d);
} catch (...) {
}
}
Exception::~Exception() throw()
{
delete d;
}
Exception::~Exception() = default;
QByteArray Exception::type() const throw()
QByteArray Exception::type() const
{
static const char mytype[] = "Akonadi::Exception";
static constexpr char mytype[] = "Akonadi::Exception";
try {
return QByteArray::fromRawData("Akonadi::Exception", sizeof(mytype) - 1);
} catch (...) {
......@@ -94,9 +82,9 @@ QByteArray Exception::type() const throw()
}
}
const char *Exception::what() const throw()
const char *Exception::what() const noexcept
{
static const char fallback[] = "<some exception was thrown during construction: message lost>";
static constexpr char fallback[] = "<some exception was thrown during construction: message lost>";
if (!d) {
return fallback;
}
......@@ -110,17 +98,18 @@ const char *Exception::what() const throw()
return d->assembledWhat.constData();
}
#define AKONADI_EXCEPTION_IMPLEMENT_TRIVIAL_INSTANCE( classname ) \
Akonadi::classname::~classname() throw() {} \
QByteArray Akonadi::classname::type() const throw() { \
static const char mytype[] = "Akonadi::" #classname ; \
try { \
#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(); \
} \
} catch ( ... ) { \
return QByteArray(); \
} \
}
AKONADI_EXCEPTION_IMPLEMENT_TRIVIAL_INSTANCE(PayloadException)
#undef AKONADI_EXCEPTION_IMPLEMENT_TRIVIAL_INSTANCE
......@@ -21,8 +21,11 @@
#define AKONADI_EXCEPTIONBASE_H
#include "akonadicore_export.h"
#include <QByteArray>
#include <exception>
#include <memory>
class QString;
......@@ -43,61 +46,57 @@ public:
/**
Creates a new exception with the error message @p what.
*/
explicit Exception(const char *what) throw();
explicit Exception(const char *what);
/**
Creates a new exception with the error message @p what.
*/
explicit Exception(const QByteArray &what) throw();
explicit Exception(const QByteArray &what);
/**
Creates a new exception with the error message @p what.
*/
explicit Exception(const QString &what) throw();
explicit Exception(const QString &what);
/**
Copy constructor.
*/
Exception(const Exception &other) throw();
Exception(const Exception &other);
Exception(Exception &&other) = default;
/**
Destructor.
*/
~Exception() throw() override;
~Exception() override;
/**
Returns the error message associated with this exception.
*/
const char *what() const throw() override;
const char *what() const noexcept override;
/**
Returns the type of this exception.
*/
virtual QByteArray type() const throw(); // ### Akonadi 2: return const char *
virtual QByteArray type() const; // ### Akonadi 2: return const char *
private:
class Private;
Private *d;
std::unique_ptr<Private> d;
};
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#define AKONADI_EXCEPTION_MAKE_TRIVIAL_INSTANCE( classname ) \
#define AKONADI_EXCEPTION_MAKE_TRIVIAL_INSTANCE(classname) \
class AKONADICORE_EXPORT classname : public Akonadi::Exception \
{ \
public: \
classname ( const char *what ) throw() : Akonadi::Exception( what ) \
{ \
} \
classname ( const QByteArray &what ) throw() : Akonadi::Exception( what ) \
{ \
} \
classname ( const QString &what ) throw() : Akonadi::Exception( what ) \
{ \
} \
~classname() throw(); \
QByteArray type() const throw() override; \
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() override; \
QByteArray type() const override; \
}
AKONADI_EXCEPTION_MAKE_TRIVIAL_INSTANCE(PayloadException);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment