File indexing completed on 2024-06-16 04:50:13

0001 /*
0002     SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "akonadicore_export.h"
0010 
0011 #include <QByteArray>
0012 
0013 #include <exception>
0014 #include <memory>
0015 
0016 class QString;
0017 
0018 namespace Akonadi
0019 {
0020 #ifdef _MSC_VER
0021 #pragma warning(push)
0022 #pragma warning(disable : 4275) // we are exporting a subclass of an unexported class, MSVC complains
0023 #endif
0024 
0025 class ExceptionPrivate;
0026 /**
0027   Base class for exceptions used by the Akonadi library.
0028 */
0029 class AKONADICORE_EXPORT Exception : public std::exception
0030 {
0031 public:
0032     /**
0033       Creates a new exception with the error message @p what.
0034     */
0035     explicit Exception(const char *what);
0036 
0037     /**
0038       Creates a new exception with the error message @p what.
0039     */
0040     explicit Exception(const QByteArray &what);
0041 
0042     /**
0043       Creates a new exception with the error message @p what.
0044     */
0045     explicit Exception(const QString &what);
0046 
0047     Exception(Exception &&) noexcept;
0048 
0049     /**
0050       Destructor.
0051     */
0052     ~Exception() override;
0053 
0054     /**
0055       Returns the error message associated with this exception.
0056     */
0057     const char *what() const noexcept override;
0058 
0059     /**
0060       Returns the type of this exception.
0061     */
0062     virtual QByteArray type() const; // ### Akonadi 2: return const char *
0063 
0064 private:
0065     std::unique_ptr<ExceptionPrivate> d;
0066 };
0067 #ifdef _MSC_VER
0068 #pragma warning(pop)
0069 #endif
0070 
0071 #define AKONADI_EXCEPTION_MAKE_TRIVIAL_INSTANCE(classname)                                                                                                     \
0072     class AKONADICORE_EXPORT classname : public Akonadi::Exception                                                                                             \
0073     {                                                                                                                                                          \
0074     public:                                                                                                                                                    \
0075         explicit classname(const char *what)                                                                                                                   \
0076             : Akonadi::Exception(what)                                                                                                                         \
0077         {                                                                                                                                                      \
0078         }                                                                                                                                                      \
0079         explicit classname(const QByteArray &what)                                                                                                             \
0080             : Akonadi::Exception(what)                                                                                                                         \
0081         {                                                                                                                                                      \
0082         }                                                                                                                                                      \
0083         explicit classname(const QString &what)                                                                                                                \
0084             : Akonadi::Exception(what)                                                                                                                         \
0085         {                                                                                                                                                      \
0086         }                                                                                                                                                      \
0087         classname(classname &&) = default;                                                                                                                     \
0088         ~classname() override;                                                                                                                                 \
0089         QByteArray type() const override;                                                                                                                      \
0090     }
0091 
0092 AKONADI_EXCEPTION_MAKE_TRIVIAL_INSTANCE(PayloadException);
0093 
0094 #undef AKONADI_EXCEPTION_MAKE_TRIVIAL_INSTANCE
0095 
0096 }