1 | /* |
2 | Copyright (c) 2009 Volker Krause <vkrause@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef AKONADI_EXCEPTION_H |
21 | #define AKONADI_EXCEPTION_H |
22 | |
23 | #include <QByteArray> |
24 | #include <QString> |
25 | #include <exception> |
26 | |
27 | namespace Akonadi { |
28 | namespace Server { |
29 | |
30 | /** |
31 | Base class for exception used internally by the Akonadi server. |
32 | */ |
33 | class Exception : public std::exception |
34 | { |
35 | public: |
36 | Exception(const char *what) throw() |
37 | : mWhat(what) |
38 | { |
39 | } |
40 | |
41 | Exception(const QByteArray &what) throw() |
42 | : mWhat(what) |
43 | { |
44 | } |
45 | |
46 | Exception(const QString &what) throw() |
47 | : mWhat(what.toUtf8()) |
48 | { |
49 | } |
50 | |
51 | Exception(const Exception &other) throw() |
52 | : std::exception(other) |
53 | , mWhat(other.what()) |
54 | { |
55 | } |
56 | |
57 | virtual ~Exception() throw() |
58 | { |
59 | } |
60 | |
61 | const char *what() const throw() |
62 | { |
63 | return mWhat.constData(); |
64 | } |
65 | |
66 | virtual const char *type() const throw() |
67 | { |
68 | return "General Exception" ; |
69 | } |
70 | protected: |
71 | QByteArray mWhat; |
72 | }; |
73 | |
74 | #define AKONADI_EXCEPTION_MAKE_INSTANCE( classname ) \ |
75 | class classname : public Akonadi::Server::Exception \ |
76 | { \ |
77 | public: \ |
78 | classname ( const char *what ) throw() \ |
79 | : Akonadi::Server::Exception( what ) \ |
80 | { \ |
81 | } \ |
82 | classname ( const QByteArray &what ) throw() \ |
83 | : Akonadi::Server::Exception( what ) \ |
84 | { \ |
85 | } \ |
86 | classname ( const QString &what ) throw() \ |
87 | : Akonadi::Server::Exception( what ) \ |
88 | { \ |
89 | } \ |
90 | const char *type() const throw() \ |
91 | { \ |
92 | return "" #classname; \ |
93 | } \ |
94 | } |
95 | |
96 | } // namespace Server |
97 | } // namespace Akonadi |
98 | |
99 | #endif |
100 | |