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

KDE's Doxygen guidelines are available online.