Akonadi

server/exception.h
1/*
2 SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
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
13namespace Akonadi
14{
15namespace Server
16{
17/**
18 Base class for exception used internally by the Akonadi server.
19*/
20class Exception : public std::exception
21{
22public:
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 &) = default;
39 Exception &operator=(const Exception &) = default;
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
53protected:
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
Base class for exception used internally by the Akonadi server.
Helper integration between Akonadi and Qt.
const char * constData() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:03:34 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.