Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 9cf536a

Browse files
committed
XmlElement::getAttribute: throw on illegal user value
Signed-off-by: David Wagner <[email protected]>
1 parent c8a6fe9 commit 9cf536a

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

xmlserializer/XmlElement.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <libxml/tree.h>
3232
#include "convert.hpp"
3333
#include <stdlib.h>
34+
#include <stdexcept>
3435

3536
using std::string;
3637

@@ -79,10 +80,6 @@ bool CXmlElement::hasAttribute(const string &strAttributeName) const
7980
template <>
8081
bool CXmlElement::getAttribute<std::string>(const string &name, string &value) const
8182
{
82-
if (!hasAttribute(name)) {
83-
return false;
84-
}
85-
8683
string backup = value;
8784
xmlChar *pucXmlValue = xmlGetProp((xmlNode *)_pXmlElement, (const xmlChar *)name.c_str());
8885
if (pucXmlValue == nullptr) {
@@ -108,7 +105,7 @@ bool CXmlElement::getAttribute(const std::string &name, T &value) const
108105
T backup = value;
109106
if (!convertTo<T>(rawValue, value)) {
110107
value = backup;
111-
return false;
108+
throw std::domain_error("\'" + rawValue + "\' could not be parsed as the requested type.");
112109
}
113110

114111
return true;

0 commit comments

Comments
 (0)