Akonadi

server/exception.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 <QByteArray>
10 #include <QString>
11 #include <exception>
12 
13 namespace Akonadi
14 {
15 namespace Server
16 {
17 /**
18  Base class for exception used internally by the Akonadi server.
19 */
20 class Exception : public std::exception
21 {
22 public:
23  explicit Exception(const char *what) noexcept
24  : mWhat(what)
25  {
26  }
27 
28  explicit Exception(const QByteArray &what) noexcept
29  : mWhat(what)
30  {
31  }
32 
33  explicit Exception(const QString &what) noexcept
34  : mWhat(what.toUtf8())
35  {
36  }
37 
38  Exception(const Exception &) = delete;
39  Exception &operator=(const Exception &) = delete;
40 
41  ~Exception() override = default;
42 
43  const char *what() const noexcept override
44  {
45  return mWhat.constData();
46  }
47 
48  virtual const char *type() const noexcept
49  {
50  return "General Exception";
51  }
52 
53 protected:
54  QByteArray mWhat;
55 };
56 
57 #define AKONADI_EXCEPTION_MAKE_INSTANCE(classname) \
58  class classname : public Akonadi::Server::Exception \
59  { \
60  public: \
61  classname(const char *what) noexcept \
62  : Akonadi::Server::Exception(what) \
63  { \
64  } \
65  classname(const QByteArray &what) noexcept \
66  : Akonadi::Server::Exception(what) \
67  { \
68  } \
69  classname(const QString &what) noexcept \
70  : Akonadi::Server::Exception(what) \
71  { \
72  } \
73  const char *type() const noexcept override \
74  { \
75  return "" #classname; \
76  } \
77  }
78 
79 } // namespace Server
80 } // namespace Akonadi
81 
Base class for exception used internally by the Akonadi server.
QByteArray toUtf8() const const
const char * constData() const const
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.