• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
exception.cpp
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 #include "exception.h"
21 
22 #include <KDebug>
23 #include <QString>
24 
25 #include <memory>
26 
27 using namespace Akonadi;
28 
29 class Exception::Private
30 {
31 public:
32  QByteArray what;
33  QByteArray assembledWhat;
34 };
35 
36 Exception::Exception(const char *what) throw()
37  : d(0)
38 {
39  try {
40  std::auto_ptr<Private> nd(new Private);
41  nd->what = what;
42  d = nd.release();
43  } catch (...) {}
44 }
45 
46 Exception::Exception(const QByteArray &what) throw()
47  : d(0)
48 {
49  try {
50  std::auto_ptr<Private> nd(new Private);
51  nd->what = what;
52  d = nd.release();
53  } catch (...) {}
54 }
55 
56 Exception::Exception(const QString &what) throw()
57  : d(0)
58 {
59  try {
60  std::auto_ptr<Private> nd(new Private);
61  nd->what = what.toUtf8();
62  d = nd.release();
63  } catch (...) {}
64 }
65 
66 Exception::Exception(const Akonadi::Exception &other) throw()
67  : std::exception(other)
68  , d(0)
69 {
70  if (!other.d) {
71  return;
72  }
73  try {
74  std::auto_ptr<Private> nd(new Private(*other.d));
75  d = nd.release();
76  } catch (...) {}
77 }
78 
79 Exception::~Exception() throw()
80 {
81  delete d;
82 }
83 
84 QByteArray Exception::type() const throw()
85 {
86  static const char mytype[] = "Akonadi::Exception";
87  try {
88  return QByteArray::fromRawData("Akonadi::Exception", sizeof (mytype) - 1);
89  } catch (...) {
90  return QByteArray();
91  }
92 }
93 
94 const char *Exception::what() const throw()
95 {
96  static const char fallback[] = "<some exception was thrown during construction: message lost>";
97  if (!d) {
98  return fallback;
99  }
100  if (d->assembledWhat.isEmpty()) {
101  try {
102  d->assembledWhat = QByteArray(type() + ": " + d->what);
103  } catch (...) {
104  return "caught some exception while assembling Akonadi::Exception::what() return value";
105  }
106  }
107  return d->assembledWhat.constData();
108 }
109 
110 #define AKONADI_EXCEPTION_IMPLEMENT_TRIVIAL_INSTANCE( classname ) \
111  Akonadi::classname::~classname() throw() {} \
112  QByteArray Akonadi::classname::type() const throw() { \
113  static const char mytype[] = "Akonadi::" #classname ; \
114  try { \
115  return QByteArray::fromRawData( mytype, sizeof (mytype)-1 ); \
116  } catch ( ... ) { \
117  return QByteArray(); \
118  } \
119  }
120 
121 AKONADI_EXCEPTION_IMPLEMENT_TRIVIAL_INSTANCE(PayloadException)
122 
123 #undef AKONADI_EXCEPTION_IMPLEMENT_TRIVIAL_INSTANCE
QByteArray
QByteArray::fromRawData
QByteArray fromRawData(const char *data, int size)
Akonadi::Exception::Exception
Exception(const char *what)
Creates a new exception with the error message what.
Definition: exception.cpp:36
Akonadi::Exception::type
virtual QByteArray type() const
Returns the type of this exception.
Definition: exception.cpp:84
QString
Akonadi::Exception::~Exception
virtual ~Exception()
Destructor.
Definition: exception.cpp:79
Akonadi::Exception
Base class for exceptions used by the Akonadi library.
Definition: exception.h:35
Akonadi::Exception::what
const char * what() const
Returns the error message associated with this exception.
Definition: exception.cpp:94
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal