exception.cpp

00001 /*
00002     Copyright (c) 2009 Volker Krause <vkrause@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "exception.h"
00021 
00022 #include <KDebug>
00023 #include <QString>
00024 
00025 namespace Akonadi {
00026 
00027 class Exception::Private
00028 {
00029   public:
00030     QByteArray what;
00031     QByteArray assembledWhat;
00032 };
00033 
00034 Exception::Exception(const char* what) throw() :
00035   d( new Private )
00036 {
00037   d->what = what;
00038 }
00039 
00040 Exception::Exception(const QByteArray& what) throw() :
00041   d( new Private )
00042 {
00043   d->what = what;
00044 }
00045 
00046 Exception::Exception(const QString& what) throw() :
00047   d( new Private )
00048 {
00049   d->what = what.toUtf8();
00050 }
00051 
00052 Exception::Exception(const Akonadi::Exception& other) throw() :
00053   std::exception( other ), d( new Private )
00054 {
00055   d->what = other.d->what;
00056 }
00057 
00058 Exception::~Exception() throw()
00059 {
00060   delete d;
00061 }
00062 
00063 QByteArray Exception::type() const throw()
00064 {
00065   return "Akonadi::Exception";
00066 }
00067 
00068 const char* Exception::what() const throw()
00069 {
00070   d->assembledWhat = QByteArray( type() + ": " + d->what );
00071   return d->assembledWhat.constData();
00072 }
00073 
00074 }
KDE Home | KDE Accessibility Home | Description of Access Keys