Kross

errorinterface.h
1 /***************************************************************************
2  * errorinterface.h
3  * This file is part of the KDE project
4  * copyright (C)2004-2006 by Sebastian Sauer ([email protected])
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  * You should have received a copy of the GNU Library General Public License
15  * along with this program; see the file COPYING. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  ***************************************************************************/
19 
20 #ifndef KROSS_ERRORINTERFACE_H
21 #define KROSS_ERRORINTERFACE_H
22 
23 #include "krossconfig.h"
24 
25 #include <QString>
26 
27 namespace Kross
28 {
29 
30 /**
31  * Interface for error-handling.
32  */
33 class KROSSCORE_EXPORT ErrorInterface
34 {
35 public:
36 
37  /**
38  * Constructor.
39  *
40  * \param error The error message.
41  * \param lineno The liner number in the scripting
42  * code where this exception got thrown.
43  */
44  ErrorInterface() {}
45 
46  /**
47  * \return true if there was an error else false is returned.
48  */
49  bool hadError() const
50  {
51  return ! m_error.isNull();
52  }
53 
54  /**
55  * \return the trace message.
56  */
57  const QString errorMessage() const
58  {
59  return m_error;
60  }
61 
62  /**
63  * \return the error message.
64  */
65  const QString errorTrace() const
66  {
67  return m_trace;
68  }
69 
70  /**
71  * \return the line number in the scripting code where the
72  * exception got thrown or -1 if there was no line number defined.
73  */
74  long errorLineNo() const
75  {
76  return m_lineno;
77  }
78 
79  /**
80  * Set the error message.
81  */
82  void setError(const QString &errormessage, const QString &tracemessage = QString(), long lineno = -1)
83  {
84  m_error = errormessage;
85  m_trace = tracemessage;
86  m_lineno = lineno;
87  krosswarning(QString::fromLatin1("Error error=%1 lineno=%2 trace=\n%3").arg(m_error).arg(m_lineno).arg(m_trace));
88  }
89 
90  /**
91  * Set the error message.
92  */
93  void setError(ErrorInterface *error)
94  {
95  m_error = error->errorMessage();
96  m_trace = error->errorTrace();
97  m_lineno = error->errorLineNo();
98  }
99 
100  /**
101  * Clear the error.
102  */
103  void clearError()
104  {
105  m_error.clear();
106  m_trace.clear();
107  m_lineno = -1;
108  }
109 
110 private:
111  /// The error message.
112  QString m_error;
113  /// The trace message.
114  QString m_trace;
115  /// The line number where the exception got thrown
116  long m_lineno;
117 };
118 
119 }
120 
121 #endif
122 
KCALUTILS_EXPORT QString errorMessage(const KCalendarCore::Exception &exception)
QString fromLatin1(const char *str, int size)
Interface for error-handling.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Dec 7 2023 04:10:00 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.