Each exception can show error message from previous.
--HG-- branch : feature
This commit is contained in:
parent
7d01bca72d
commit
4d210ddd48
|
@ -31,11 +31,16 @@
|
|||
#include <QSpacerItem>
|
||||
#include <QGridLayout>
|
||||
|
||||
VException::VException(const QString &what):QException(), what(what)
|
||||
VException::VException(const QString &what):QException(), what(what), moreInfo(QString())
|
||||
{
|
||||
Q_ASSERT_X(what.isEmpty() == false, Q_FUNC_INFO, "Error message is empty");
|
||||
}
|
||||
|
||||
VException::VException(const VException &e):what(e.What()), moreInfo(e.MoreInformation())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString VException::ErrorMessage() const
|
||||
{
|
||||
QString error = QString("Exception: %1").arg(what);
|
||||
|
@ -61,3 +66,24 @@ void VException::CriticalMessageBox(const QString &situation, QWidget * parent)
|
|||
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
|
||||
msgBox.exec();
|
||||
}
|
||||
|
||||
void VException::AddMoreInformation(const QString &info)
|
||||
{
|
||||
if (info.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
moreInfo = QString("%1\n%2").arg(moreInfo, info);
|
||||
}
|
||||
|
||||
QString VException::MoreInfo(const QString &detInfo) const
|
||||
{
|
||||
if (moreInfo.isEmpty() == false)
|
||||
{
|
||||
return QString("%1\n%2").arg(moreInfo, detInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
return detInfo;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
* @brief VException copy constructor
|
||||
* @param e exception
|
||||
*/
|
||||
VException(const VException &e):what(e.What()){}
|
||||
VException(const VException &e);
|
||||
virtual ~VException() noexcept (true){}
|
||||
/**
|
||||
* @brief raise method raise for exception
|
||||
|
@ -69,7 +69,7 @@ public:
|
|||
* @brief DetailedInformation return detailed information about error
|
||||
* @return detailed information
|
||||
*/
|
||||
virtual QString DetailedInformation() const { return QString(); }
|
||||
virtual QString DetailedInformation() const;
|
||||
/**
|
||||
* @brief What return string with error
|
||||
* @return string with error
|
||||
|
@ -80,11 +80,26 @@ public:
|
|||
* @param situation main text message box.
|
||||
*/
|
||||
virtual void CriticalMessageBox(const QString &situation, QWidget *parent = nullptr) const;
|
||||
/**
|
||||
* @brief AddMoreInformation add more information for error
|
||||
* @param info information
|
||||
*/
|
||||
void AddMoreInformation(const QString &info);
|
||||
/**
|
||||
* @brief MoreInformation return more information for error
|
||||
* @return information
|
||||
*/
|
||||
QString MoreInformation() const;
|
||||
protected:
|
||||
/**
|
||||
* @brief what string with error
|
||||
*/
|
||||
QString what;
|
||||
/**
|
||||
* @brief moreInfo more information about error
|
||||
*/
|
||||
QString moreInfo;
|
||||
QString MoreInfo(const QString &detInfo) const;
|
||||
};
|
||||
|
||||
inline void VException::raise() const
|
||||
|
@ -97,9 +112,19 @@ inline VException *VException::clone() const
|
|||
return new VException(*this);
|
||||
}
|
||||
|
||||
inline QString VException::DetailedInformation() const
|
||||
{
|
||||
return moreInfo;
|
||||
}
|
||||
|
||||
inline QString VException::What() const
|
||||
{
|
||||
return what;
|
||||
}
|
||||
|
||||
inline QString VException::MoreInformation() const
|
||||
{
|
||||
return moreInfo;
|
||||
}
|
||||
|
||||
#endif // VEXCEPTION_H
|
||||
|
|
|
@ -56,6 +56,5 @@ QString VExceptionEmptyParameter::ErrorMessage() const
|
|||
|
||||
QString VExceptionEmptyParameter::DetailedInformation() const
|
||||
{
|
||||
QString detail = QString("tag: %1 in line %2\nFull tag:\n%3").arg(tagName).arg(lineNumber).arg(tagText);
|
||||
return detail;
|
||||
return MoreInfo(QString("tag: %1 in line %2\nFull tag:\n%3").arg(tagName).arg(lineNumber).arg(tagText));
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <QDebug>
|
||||
|
||||
VExceptionObjectError::VExceptionObjectError(const QString &what, const QDomElement &domElement)
|
||||
:VException(what), tagText(QString()), tagName(QString()), lineNumber(-1), moreInfo(QString())
|
||||
:VException(what), tagText(QString()), tagName(QString()), lineNumber(-1)
|
||||
{
|
||||
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
||||
QTextStream stream(&tagText);
|
||||
|
@ -40,8 +40,7 @@ VExceptionObjectError::VExceptionObjectError(const QString &what, const QDomElem
|
|||
}
|
||||
|
||||
VExceptionObjectError::VExceptionObjectError(const VExceptionObjectError &e)
|
||||
:VException(e), tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()),
|
||||
moreInfo(e.MoreInformation())
|
||||
:VException(e), tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber())
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -54,24 +53,5 @@ QString VExceptionObjectError::ErrorMessage() const
|
|||
|
||||
QString VExceptionObjectError::DetailedInformation() const
|
||||
{
|
||||
QString detail;
|
||||
if (moreInfo.isEmpty() == false)
|
||||
{
|
||||
QString i = QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText);
|
||||
detail = QString("%1\n%2").arg(moreInfo, i);
|
||||
}
|
||||
else
|
||||
{
|
||||
detail = QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText);
|
||||
}
|
||||
return detail;
|
||||
}
|
||||
|
||||
void VExceptionObjectError::AddMoreInformation(const QString &info)
|
||||
{
|
||||
if (info.isEmpty())
|
||||
{
|
||||
qWarning()<<"Error additional information is empty."<<Q_FUNC_INFO;
|
||||
}
|
||||
this->moreInfo.append(info);
|
||||
return MoreInfo(QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText));
|
||||
}
|
||||
|
|
|
@ -76,16 +76,6 @@ public:
|
|||
* @return line number
|
||||
*/
|
||||
qint32 LineNumber() const;
|
||||
/**
|
||||
* @brief AddMoreInformation add more information for error
|
||||
* @param info information
|
||||
*/
|
||||
void AddMoreInformation(const QString &info);
|
||||
/**
|
||||
* @brief MoreInformation return more information for error
|
||||
* @return information
|
||||
*/
|
||||
QString MoreInformation() const;
|
||||
protected:
|
||||
/**
|
||||
* @brief tagText tag text
|
||||
|
@ -99,10 +89,6 @@ protected:
|
|||
* @brief lineNumber line number
|
||||
*/
|
||||
qint32 lineNumber;
|
||||
/**
|
||||
* @brief moreInfo more information about error
|
||||
*/
|
||||
QString moreInfo;
|
||||
};
|
||||
|
||||
inline QString VExceptionObjectError::TagText() const
|
||||
|
@ -120,9 +106,4 @@ inline qint32 VExceptionObjectError::LineNumber() const
|
|||
return lineNumber;
|
||||
}
|
||||
|
||||
inline QString VExceptionObjectError::MoreInformation() const
|
||||
{
|
||||
return moreInfo;
|
||||
}
|
||||
|
||||
#endif // VEXCEPTIONOBJECTERROR_H
|
||||
|
|
|
@ -53,6 +53,5 @@ QString VExceptionWrongId::ErrorMessage() const
|
|||
|
||||
QString VExceptionWrongId::DetailedInformation() const
|
||||
{
|
||||
QString detail = QString("tag: %1 in line %2\nFull tag:\n%3").arg(tagName).arg(lineNumber).arg(tagText);
|
||||
return detail;
|
||||
return MoreInfo(QString("tag: %1 in line %2\nFull tag:\n%3").arg(tagName).arg(lineNumber).arg(tagText));
|
||||
}
|
||||
|
|
|
@ -150,13 +150,28 @@ quint32 VDomDocument::GetParametrUInt(const QDomElement &domElement, const QStri
|
|||
{
|
||||
Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "name of parametr is empty");
|
||||
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
||||
|
||||
bool ok = false;
|
||||
const QString parametr = GetParametrString(domElement, name, defValue);
|
||||
const quint32 id = parametr.toUInt(&ok);
|
||||
if (ok == false)
|
||||
QString parametr;
|
||||
quint32 id = 0;
|
||||
|
||||
QString message = tr("Can't convert toUInt parameter");
|
||||
try
|
||||
{
|
||||
throw VExceptionConversionError(tr("Can't convert toUInt parameter"), name);
|
||||
parametr = GetParametrString(domElement, name, defValue);
|
||||
id = parametr.toUInt(&ok);
|
||||
if (ok == false)
|
||||
{
|
||||
throw VExceptionConversionError(message, name);
|
||||
}
|
||||
}
|
||||
catch (const VExceptionEmptyParameter &e)
|
||||
{
|
||||
VExceptionConversionError excep(message, name);
|
||||
excep.AddMoreInformation(e.ErrorMessage());
|
||||
throw excep;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
@ -184,12 +199,25 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri
|
|||
{
|
||||
Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "name of parametr is empty");
|
||||
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
||||
|
||||
bool ok = false;
|
||||
QString parametr = GetParametrString(domElement, name, defValue);
|
||||
const qreal param = parametr.replace(",", ".").toDouble(&ok);
|
||||
if (ok == false)
|
||||
qreal param = 0;
|
||||
|
||||
QString message = tr("Can't convert toDouble parameter");
|
||||
try
|
||||
{
|
||||
throw VExceptionConversionError(tr("Can't convert toDouble parameter"), name);
|
||||
QString parametr = GetParametrString(domElement, name, defValue);
|
||||
param = parametr.replace(",", ".").toDouble(&ok);
|
||||
if (ok == false)
|
||||
{
|
||||
throw VExceptionConversionError(message, name);
|
||||
}
|
||||
}
|
||||
catch (const VExceptionEmptyParameter &e)
|
||||
{
|
||||
VExceptionConversionError excep(message, name);
|
||||
excep.AddMoreInformation(e.ErrorMessage());
|
||||
throw excep;
|
||||
}
|
||||
return param;
|
||||
}
|
||||
|
|
|
@ -88,8 +88,11 @@ public:
|
|||
const QString &defValue) const;
|
||||
/**
|
||||
* @brief GetParametrString return string value of attribute.
|
||||
*
|
||||
* if attribute empty return default value. If default value empty too throw exception.
|
||||
* @param domElement tag in xml tree.
|
||||
* @param name attribute name.
|
||||
* @throw VExceptionEmptyParameter when attribute is empty
|
||||
* @return attribute value.
|
||||
*/
|
||||
QString GetParametrString(const QDomElement& domElement, const QString &name,
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "../tools/nodeDetails/nodedetails.h"
|
||||
#include "../exception/vexceptionobjecterror.h"
|
||||
#include "../exception/vexceptionwrongid.h"
|
||||
#include "../exception/vexceptionconversionerror.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
|
@ -1244,10 +1245,23 @@ void VPattern::ParseIncrementsElement(const QDomNode &node)
|
|||
quint32 VPattern::GetParametrId(const QDomElement &domElement) const
|
||||
{
|
||||
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
||||
const quint32 id = GetParametrUInt(domElement, VAbstractTool::AttrId, "0");
|
||||
if (id <= 0)
|
||||
|
||||
quint32 id = 0;
|
||||
|
||||
QString message = tr("Got wrong parameter id. Need only id > 0.");
|
||||
try
|
||||
{
|
||||
throw VExceptionWrongId(tr("Got wrong parameter id. Need only id > 0."), domElement);
|
||||
id = GetParametrUInt(domElement, VAbstractTool::AttrId, "0");
|
||||
if (id <= 0)
|
||||
{
|
||||
throw VExceptionWrongId(message, domElement);
|
||||
}
|
||||
}
|
||||
catch (const VExceptionConversionError &e)
|
||||
{
|
||||
VExceptionWrongId excep(message, domElement);
|
||||
excep.AddMoreInformation(e.ErrorMessage());
|
||||
throw excep;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user