File indexing completed on 2024-04-14 14:27:09
0001 /*************************************************************************** 0002 * errorinterface.h 0003 * This file is part of the KDE project 0004 * copyright (C)2004-2006 by Sebastian Sauer (mail@dipe.org) 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this program; see the file COPYING. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 ***************************************************************************/ 0019 0020 #ifndef KROSS_ERRORINTERFACE_H 0021 #define KROSS_ERRORINTERFACE_H 0022 0023 #include "krossconfig.h" 0024 0025 #include <QString> 0026 0027 namespace Kross 0028 { 0029 0030 /** 0031 * Interface for error-handling. 0032 */ 0033 class KROSSCORE_EXPORT ErrorInterface 0034 { 0035 public: 0036 0037 /** 0038 * Constructor. 0039 * 0040 * \param error The error message. 0041 * \param lineno The liner number in the scripting 0042 * code where this exception got thrown. 0043 */ 0044 ErrorInterface() {} 0045 0046 /** 0047 * \return true if there was an error else false is returned. 0048 */ 0049 bool hadError() const 0050 { 0051 return ! m_error.isNull(); 0052 } 0053 0054 /** 0055 * \return the trace message. 0056 */ 0057 const QString errorMessage() const 0058 { 0059 return m_error; 0060 } 0061 0062 /** 0063 * \return the error message. 0064 */ 0065 const QString errorTrace() const 0066 { 0067 return m_trace; 0068 } 0069 0070 /** 0071 * \return the line number in the scripting code where the 0072 * exception got thrown or -1 if there was no line number defined. 0073 */ 0074 long errorLineNo() const 0075 { 0076 return m_lineno; 0077 } 0078 0079 /** 0080 * Set the error message. 0081 */ 0082 void setError(const QString &errormessage, const QString &tracemessage = QString(), long lineno = -1) 0083 { 0084 m_error = errormessage; 0085 m_trace = tracemessage; 0086 m_lineno = lineno; 0087 krosswarning(QString::fromLatin1("Error error=%1 lineno=%2 trace=\n%3").arg(m_error).arg(m_lineno).arg(m_trace)); 0088 } 0089 0090 /** 0091 * Set the error message. 0092 */ 0093 void setError(ErrorInterface *error) 0094 { 0095 m_error = error->errorMessage(); 0096 m_trace = error->errorTrace(); 0097 m_lineno = error->errorLineNo(); 0098 } 0099 0100 /** 0101 * Clear the error. 0102 */ 0103 void clearError() 0104 { 0105 m_error.clear(); 0106 m_trace.clear(); 0107 m_lineno = -1; 0108 } 0109 0110 private: 0111 /// The error message. 0112 QString m_error; 0113 /// The trace message. 0114 QString m_trace; 0115 /// The line number where the exception got thrown 0116 long m_lineno; 0117 }; 0118 0119 } 0120 0121 #endif 0122