Akonadi

exceptionbase.h
1 /*
2  SPDX-FileCopyrightText: 2009 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "akonadicore_export.h"
10 
11 #include <QByteArray>
12 
13 #include <exception>
14 #include <memory>
15 
16 class QString;
17 
18 namespace Akonadi
19 {
20 #ifdef _MSC_VER
21 #pragma warning(push)
22 #pragma warning(disable : 4275) // we are exporting a subclass of an unexported class, MSVC complains
23 #endif
24 
25 class ExceptionPrivate;
26 /**
27  Base class for exceptions used by the Akonadi library.
28 */
29 class AKONADICORE_EXPORT Exception : public std::exception
30 {
31 public:
32  /**
33  Creates a new exception with the error message @p what.
34  */
35  explicit Exception(const char *what);
36 
37  /**
38  Creates a new exception with the error message @p what.
39  */
40  explicit Exception(const QByteArray &what);
41 
42  /**
43  Creates a new exception with the error message @p what.
44  */
45  explicit Exception(const QString &what);
46 
47  Exception(Exception &&) noexcept;
48 
49  /**
50  Destructor.
51  */
52  ~Exception() override;
53 
54  /**
55  Returns the error message associated with this exception.
56  */
57  const char *what() const noexcept override;
58 
59  /**
60  Returns the type of this exception.
61  */
62  virtual QByteArray type() const; // ### Akonadi 2: return const char *
63 
64 private:
65  std::unique_ptr<ExceptionPrivate> d;
66 };
67 #ifdef _MSC_VER
68 #pragma warning(pop)
69 #endif
70 
71 #define AKONADI_EXCEPTION_MAKE_TRIVIAL_INSTANCE(classname) \
72  class AKONADICORE_EXPORT classname : public Akonadi::Exception \
73  { \
74  public: \
75  explicit classname(const char *what) \
76  : Akonadi::Exception(what) \
77  { \
78  } \
79  explicit classname(const QByteArray &what) \
80  : Akonadi::Exception(what) \
81  { \
82  } \
83  explicit classname(const QString &what) \
84  : Akonadi::Exception(what) \
85  { \
86  } \
87  classname(classname &&) = default; \
88  ~classname() override; \
89  QByteArray type() const override; \
90  }
91 
92 AKONADI_EXCEPTION_MAKE_TRIVIAL_INSTANCE(PayloadException);
93 
94 #undef AKONADI_EXCEPTION_MAKE_TRIVIAL_INSTANCE
95 
96 }
Base class for exceptions used by the Akonadi library.
Definition: exceptionbase.h:29
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Dec 6 2022 03:53:33 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.