Seamly2D
Code documentation
vexception.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file vexception.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date November 15, 2013
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2013-2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "vexception.h"
53 
54 #include <QByteArray>
55 #include <QtGlobal>
56 
57 #include "../ifcdef.h"
58 
59 //Q_LOGGING_CATEGORY(vExcep, "v.excep") //Commented because don't use now
60 
61 //---------------------------------------------------------------------------------------------------------------------
62 /**
63  * @brief VException constructor exception
64  * @param error string with error
65  */
66 VException::VException(const QString &error)
67  :QException(), error(error), moreInfo(QString())
68 {
69  Q_ASSERT_X(not error.isEmpty(), Q_FUNC_INFO, "Error message is empty");
70 }
71 
72 //---------------------------------------------------------------------------------------------------------------------
73 /**
74  * @brief VException copy constructor
75  * @param e exception
76  */
77 VException::VException(const VException &e):error(e.WhatUtf8()), moreInfo(e.MoreInformation())
78 {}
79 
80 //---------------------------------------------------------------------------------------------------------------------
82 {
83  if ( &e == this )
84  {
85  return *this;
86  }
87  this->error = e.WhatUtf8();
88  this->moreInfo = e.MoreInformation();
89  return *this;
90 }
91 
92 //---------------------------------------------------------------------------------------------------------------------
93 /**
94  * @brief ErrorMessage return main error message
95  * @return error message
96  */
97 QString VException::ErrorMessage() const
98 {
99  return tr("Exception: %1").arg(error);
100 }
101 
102 //---------------------------------------------------------------------------------------------------------------------
103 /**
104  * @brief AddMoreInformation add more information for error
105  * @param info information
106  */
107 void VException::AddMoreInformation(const QString &info)
108 {
109  if (info.isEmpty())
110  {
111  return;
112  }
113  moreInfo = QString("%1\n%2").arg(moreInfo, info);
114 }
115 
116 //---------------------------------------------------------------------------------------------------------------------
117 QString VException::MoreInfo(const QString &detInfo) const
118 {
119  if (moreInfo.isEmpty() == false)
120  {
121  return QString("%1\n%2").arg(moreInfo, detInfo);
122  }
123  else
124  {
125  return detInfo;
126  }
127 }
128 
129 //---------------------------------------------------------------------------------------------------------------------
130 /**
131  * @brief DetailedInformation return detailed information about error
132  * @return detailed information
133  */
135 {
136  return moreInfo;
137 }
138 
139 //---------------------------------------------------------------------------------------------------------------------
140 /**
141  * @brief clone clone exception
142  * @return new exception
143  */
144 // cppcheck-suppress unusedFunction
146 {
147  return new VException(*this);
148 }
149 
150 //---------------------------------------------------------------------------------------------------------------------
151 /**
152  * @brief raise method raise for exception
153  */
154 // cppcheck-suppress unusedFunction
155 Q_NORETURN void VException::raise() const
156 {
157  throw *this;
158 }
159 
160 //---------------------------------------------------------------------------------------------------------------------
161 const char* VException::what() const V_NOEXCEPT_EXPR (true)
162 {
163  return error.toUtf8().constData();
164 }
165 
166 //-----------------------------------------VExceptionToolWasDeleted----------------------------------------------------
168  :VException(error)
169 {
170 }
171 
172 //---------------------------------------------------------------------------------------------------------------------
174  :VException(e)
175 {
176 }
177 
178 //---------------------------------------------------------------------------------------------------------------------
180 {
181  if ( &e == this )
182  {
183  return *this;
184  }
186  return *this;
187 }
188 
189 //---------------------------------------------------------------------------------------------------------------------
190 /**
191  * @brief raise method raise for exception
192  */
193 // cppcheck-suppress unusedFunction
194 Q_NORETURN void VExceptionToolWasDeleted::raise() const
195 {
196  throw *this;
197 }
198 
199 //---------------------------------------------------------------------------------------------------------------------
201 {
202  return new VExceptionToolWasDeleted(*this);
203 }
virtual VExceptionToolWasDeleted * clone() const Q_DECL_OVERRIDE
clone clone exception
Definition: vexception.cpp:200
VExceptionToolWasDeleted(const QString &error)
Definition: vexception.cpp:167
virtual Q_NORETURN void raise() const Q_DECL_OVERRIDE
raise method raise for exception
Definition: vexception.cpp:194
VExceptionToolWasDeleted & operator=(const VExceptionToolWasDeleted &e)
Definition: vexception.cpp:179
The VException class parent for all exception. Could be use for abstract exception.
Definition: vexception.h:66
virtual Q_REQUIRED_RESULT VException * clone() const Q_DECL_OVERRIDE
clone clone exception
Definition: vexception.cpp:145
QString MoreInfo(const QString &detInfo) const
Definition: vexception.cpp:117
VException(const QString &error)
VException constructor exception.
Definition: vexception.cpp:66
QString MoreInformation() const
MoreInformation return more information for error.
Definition: vexception.h:111
virtual QString ErrorMessage() const
ErrorMessage return main error message.
Definition: vexception.cpp:97
QString error
error string with error
Definition: vexception.h:88
void AddMoreInformation(const QString &info)
AddMoreInformation add more information for error.
Definition: vexception.cpp:107
virtual const char * what() const Q_DECL_OVERRIDE
Definition: vexception.cpp:161
QString moreInfo
moreInfo more information about error
Definition: vexception.h:91
VException & operator=(const VException &e)
Definition: vexception.cpp:81
QString WhatUtf8() const
What return string with error.
Definition: vexception.h:101
virtual QString DetailedInformation() const
DetailedInformation return detailed information about error.
Definition: vexception.cpp:134
virtual Q_NORETURN void raise() const Q_DECL_OVERRIDE
raise method raise for exception
Definition: vexception.cpp:155
#define V_NOEXCEPT_EXPR(x)
Definition: ifcdef.h:91