exception.h

00001 /***************************************************************************
00002  * exception.h
00003  * This file is part of the KDE project
00004  * copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org)
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this program; see the file COPYING.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  ***************************************************************************/
00019 
00020 #ifndef KROSS_API_EXCEPTION_H
00021 #define KROSS_API_EXCEPTION_H
00022 
00023 #include "object.h"
00024 
00025 #include <qstring.h>
00026 #include <ksharedptr.h>
00027 
00028 namespace Kross { namespace Api {
00029 
00030     /**
00031      * Common exception class used for representing exceptions
00032      * in Kross.
00033      *
00034      * Internal we use \a Exception instances to throw and handle
00035      * exceptions. Those exceptions are inherited from \a Object
00036      * and therefore they are first class citizens in Kross.
00037      */
00038     class Exception : public Object
00039     {
00040         private:
00041 
00042             /// The error message.
00043             QString m_error;
00044 
00045             /// The trace message.
00046             QString m_trace;
00047 
00048             /// The line number where the exception got thrown
00049             long m_lineno;
00050 
00051         public:
00052 
00053             /**
00054              * Shared pointer to implement reference-counting.
00055              */
00056             typedef KSharedPtr<Exception> Ptr;
00057 
00058             /**
00059              * Constructor.
00060              *
00061              * \param error The error message.
00062              * \param lineno The liner number in the scripting
00063              *        code where this exception got thrown.
00064              * \param parent The parent \a Object or NULL if
00065              *        this exception object doesn't has a
00066              *        parent.
00067              */
00068             Exception(const QString& error, long lineno = -1, Object::Ptr parent = 0);
00069 
00070             /**
00071              * Destructor.
00072              */
00073             virtual ~Exception();
00074 
00075             /// \see Kross::Api::Object::getClassName()
00076             virtual const QString getClassName() const;
00077 
00078             /// \see Kross::Api::Object::toString()
00079             virtual const QString toString();
00080 
00081             /**
00082              * \return the error message.
00083              */
00084             const QString& getError() const;
00085 
00086             /**
00087              * \return a more detailed tracemessage or QString::null if
00088              * there is no trace avaiable.
00089              */
00090             const QString& getTrace() const;
00091 
00092             /**
00093              * Set a more detailed tracemessage.
00094              */
00095             void setTrace(const QString& tracemessage);
00096 
00097             /**
00098              * \return the line number in the scripting code
00099              * where the exception got thrown or -1 if there
00100              * was no line number defined.
00101              */
00102             long getLineNo() const;
00103     };
00104 
00105 }}
00106 
00107 #endif
00108 

Generated on Thu Feb 9 17:59:10 2006 for Kross by  doxygen 1.4.6