Enhance exception throwing with Boost Exception library
Change-Id: I471023fc23ffaebe04d9668426b4c1b03e4962ba
Refs: #2997
diff --git a/src/security/conf/checker.hpp b/src/security/conf/checker.hpp
index 1364229..bb651bc 100644
--- a/src/security/conf/checker.hpp
+++ b/src/security/conf/checker.hpp
@@ -104,14 +104,14 @@
case tlv::SignatureSha256WithEcdsa:
{
if (!static_cast<bool>(m_keyLocatorChecker))
- throw Error("Strong signature requires KeyLocatorChecker");
+ BOOST_THROW_EXCEPTION(Error("Strong signature requires KeyLocatorChecker"));
return;
}
case tlv::DigestSha256:
return;
default:
- throw Error("Unsupported signature type");
+ BOOST_THROW_EXCEPTION(Error("Unsupported signature type"));
}
}
@@ -245,7 +245,7 @@
if (sigType != tlv::SignatureSha256WithRsa &&
sigType != tlv::SignatureSha256WithEcdsa)
{
- throw Error("FixedSigner is only meaningful for strong signature type");
+ BOOST_THROW_EXCEPTION(Error("FixedSigner is only meaningful for strong signature type"));
}
}
@@ -389,7 +389,7 @@
// Get checker.type
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type"))
- throw Error("Expect <checker.type>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.type>"));
std::string type = propertyIt->second.data();
@@ -400,7 +400,7 @@
else if (boost::iequals(type, "fixed-signer"))
return createFixedSignerChecker(configSection, configFilename);
else
- throw Error("Unsupported checker type: " + type);
+ BOOST_THROW_EXCEPTION(Error("Unsupported checker type: " + type));
}
private:
@@ -413,21 +413,21 @@
// Get checker.sig-type
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "sig-type"))
- throw Error("Expect <checker.sig-type>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.sig-type>"));
std::string sigType = propertyIt->second.data();
propertyIt++;
// Get checker.key-locator
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "key-locator"))
- throw Error("Expect <checker.key-locator>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator>"));
shared_ptr<KeyLocatorChecker> keyLocatorChecker =
KeyLocatorCheckerFactory::create(propertyIt->second, configFilename);
propertyIt++;
if (propertyIt != configSection.end())
- throw Error("Expect the end of checker");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker"));
return make_shared<CustomizedChecker>(getSigType(sigType), keyLocatorChecker);
}
@@ -441,13 +441,13 @@
// Get checker.sig-type
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "sig-type"))
- throw Error("Expect <checker.sig-type>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.sig-type>"));
std::string sigType = propertyIt->second.data();
propertyIt++;
if (propertyIt != configSection.end())
- throw Error("Expect the end of checker");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker"));
return make_shared<HierarchicalChecker>(getSigType(sigType));
}
@@ -461,7 +461,7 @@
// Get checker.sig-type
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "sig-type"))
- throw Error("Expect <checker.sig-type>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.sig-type>"));
std::string sigType = propertyIt->second.data();
propertyIt++;
@@ -470,14 +470,14 @@
for (; propertyIt != configSection.end(); propertyIt++)
{
if (!boost::iequals(propertyIt->first, "signer"))
- throw Error("Expect <checker.signer> but get <checker." +
- propertyIt->first + ">");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.signer> but get <checker." +
+ propertyIt->first + ">"));
signers.push_back(getSigner(propertyIt->second, configFilename));
}
if (propertyIt != configSection.end())
- throw Error("Expect the end of checker");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker"));
return shared_ptr<FixedSignerChecker>(new FixedSignerChecker(getSigType(sigType),
signers));
@@ -492,7 +492,7 @@
// Get checker.signer.type
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type"))
- throw Error("Expect <checker.signer.type>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.signer.type>"));
std::string type = propertyIt->second.data();
propertyIt++;
@@ -501,14 +501,14 @@
{
// Get checker.signer.file-name
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "file-name"))
- throw Error("Expect <checker.signer.file-name>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.signer.file-name>"));
path certfilePath = absolute(propertyIt->second.data(),
path(configFilename).parent_path());
propertyIt++;
if (propertyIt != configSection.end())
- throw Error("Expect the end of checker.signer");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker.signer"));
shared_ptr<IdentityCertificate> idCert
= io::load<IdentityCertificate>(certfilePath.c_str());
@@ -516,31 +516,31 @@
if (static_cast<bool>(idCert))
return idCert;
else
- throw Error("Cannot read certificate from file: " +
- certfilePath.native());
+ BOOST_THROW_EXCEPTION(Error("Cannot read certificate from file: " +
+ certfilePath.native()));
}
else if (boost::iequals(type, "base64"))
{
// Get checker.signer.base64-string
if (propertyIt == configSection.end() ||
!boost::iequals(propertyIt->first, "base64-string"))
- throw Error("Expect <checker.signer.base64-string>");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.signer.base64-string>"));
std::stringstream ss(propertyIt->second.data());
propertyIt++;
if (propertyIt != configSection.end())
- throw Error("Expect the end of checker.signer");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker.signer"));
shared_ptr<IdentityCertificate> idCert = io::load<IdentityCertificate>(ss);
if (static_cast<bool>(idCert))
return idCert;
else
- throw Error("Cannot decode certificate from string");
+ BOOST_THROW_EXCEPTION(Error("Cannot decode certificate from string"));
}
else
- throw Error("Unsupported checker.signer type: " + type);
+ BOOST_THROW_EXCEPTION(Error("Unsupported checker.signer type: " + type));
}
static uint32_t
@@ -553,7 +553,7 @@
else if (boost::iequals(sigType, "sha256"))
return tlv::DigestSha256;
else
- throw Error("Unsupported signature type");
+ BOOST_THROW_EXCEPTION(Error("Unsupported signature type"));
}
};
diff --git a/src/security/conf/filter.hpp b/src/security/conf/filter.hpp
index 8d0601c..3dfddde 100644
--- a/src/security/conf/filter.hpp
+++ b/src/security/conf/filter.hpp
@@ -152,14 +152,14 @@
ConfigSection::const_iterator propertyIt = configSection.begin();
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type"))
- throw Error("Expect <filter.type>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <filter.type>!"));
std::string type = propertyIt->second.data();
if (boost::iequals(type, "name"))
return createNameFilter(configSection);
else
- throw Error("Unsupported filter.type: " + type);
+ BOOST_THROW_EXCEPTION(Error("Unsupported filter.type: " + type));
}
private:
static shared_ptr<Filter>
@@ -169,7 +169,7 @@
propertyIt++;
if (propertyIt == configSection.end())
- throw Error("Expect more properties for filter(name)");
+ BOOST_THROW_EXCEPTION(Error("Expect more properties for filter(name)"));
if (boost::iequals(propertyIt->first, "name"))
{
@@ -181,14 +181,14 @@
}
catch (Name::Error& e)
{
- throw Error("Wrong filter.name: " + propertyIt->second.data());
+ BOOST_THROW_EXCEPTION(Error("Wrong filter.name: " + propertyIt->second.data()));
}
propertyIt++;
// Get filter.relation
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "relation"))
- throw Error("Expect <filter.relation>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <filter.relation>!"));
std::string relationString = propertyIt->second.data();
propertyIt++;
@@ -201,11 +201,11 @@
else if (boost::iequals(relationString, "is-strict-prefix-of"))
relation = RelationNameFilter::RELATION_IS_STRICT_PREFIX_OF;
else
- throw Error("Unsupported relation: " + relationString);
+ BOOST_THROW_EXCEPTION(Error("Unsupported relation: " + relationString));
if (propertyIt != configSection.end())
- throw Error("Expect the end of filter!");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of filter!"));
return make_shared<RelationNameFilter>(name, relation);
}
@@ -215,7 +215,7 @@
propertyIt++;
if (propertyIt != configSection.end())
- throw Error("Expect the end of filter!");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of filter!"));
try
{
@@ -223,11 +223,11 @@
}
catch (Regex::Error& e)
{
- throw Error("Wrong filter.regex: " + regexString);
+ BOOST_THROW_EXCEPTION(Error("Wrong filter.regex: " + regexString));
}
}
else
- throw Error("Wrong filter(name) properties");
+ BOOST_THROW_EXCEPTION(Error("Wrong filter(name) properties"));
}
};
diff --git a/src/security/conf/key-locator-checker.hpp b/src/security/conf/key-locator-checker.hpp
index 7d5bb9c..667dfeb 100644
--- a/src/security/conf/key-locator-checker.hpp
+++ b/src/security/conf/key-locator-checker.hpp
@@ -234,14 +234,14 @@
// Get checker.key-locator.type
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type"))
- throw Error("Expect <checker.key-locator.type>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.type>!"));
std::string type = propertyIt->second.data();
if (boost::iequals(type, "name"))
return createKeyLocatorNameChecker(configSection, filename);
else
- throw Error("Unsupported checker.key-locator.type: " + type);
+ BOOST_THROW_EXCEPTION(Error("Unsupported checker.key-locator.type: " + type));
}
private:
@@ -253,7 +253,7 @@
propertyIt++;
if (propertyIt == configSection.end())
- throw Error("Expect more checker.key-locator properties");
+ BOOST_THROW_EXCEPTION(Error("Expect more checker.key-locator properties"));
if (boost::iequals(propertyIt->first, "name"))
{
@@ -264,13 +264,13 @@
}
catch (Name::Error& e)
{
- throw Error("Invalid checker.key-locator.name: " +
- propertyIt->second.data());
+ BOOST_THROW_EXCEPTION(Error("Invalid checker.key-locator.name: " +
+ propertyIt->second.data()));
}
propertyIt++;
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "relation"))
- throw Error("Expect <checker.key-locator.relation>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.relation>!"));
std::string relationString = propertyIt->second.data();
propertyIt++;
@@ -283,10 +283,10 @@
else if (boost::iequals(relationString, "is-strict-prefix-of"))
relation = KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF;
else
- throw Error("Unsupported relation: " + relationString);
+ BOOST_THROW_EXCEPTION(Error("Unsupported relation: " + relationString));
if (propertyIt != configSection.end())
- throw Error("Expect the end of checker.key-locator!");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker.key-locator!"));
return shared_ptr<RelationKeyLocatorNameChecker>
(new RelationKeyLocatorNameChecker(name, relation));
@@ -297,7 +297,7 @@
propertyIt++;
if (propertyIt != configSection.end())
- throw Error("Expect the end of checker.key-locator!");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker.key-locator!"));
try
{
@@ -306,7 +306,7 @@
}
catch (Regex::Error& e)
{
- throw Error("Invalid checker.key-locator.regex: " + regexString);
+ BOOST_THROW_EXCEPTION(Error("Invalid checker.key-locator.regex: " + regexString));
}
}
else if (boost::iequals(propertyIt->first, "hyper-relation"))
@@ -317,41 +317,41 @@
// Get k-regex
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "k-regex"))
- throw Error("Expect <checker.key-locator.hyper-relation.k-regex>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.k-regex>!"));
std::string kRegex = hPropertyIt->second.data();
hPropertyIt++;
// Get k-expand
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "k-expand"))
- throw Error("Expect <checker.key-locator.hyper-relation.k-expand>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.k-expand>!"));
std::string kExpand = hPropertyIt->second.data();
hPropertyIt++;
// Get h-relation
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "h-relation"))
- throw Error("Expect <checker.key-locator.hyper-relation.h-relation>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.h-relation>!"));
std::string hRelation = hPropertyIt->second.data();
hPropertyIt++;
// Get p-regex
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "p-regex"))
- throw Error("Expect <checker.key-locator.hyper-relation.p-regex>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.p-regex>!"));
std::string pRegex = hPropertyIt->second.data();
hPropertyIt++;
// Get p-expand
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "p-expand"))
- throw Error("Expect <checker.key-locator.hyper-relation.p-expand>!");
+ BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.p-expand>!"));
std::string pExpand = hPropertyIt->second.data();
hPropertyIt++;
if (hPropertyIt != hSection.end())
- throw Error("Expect the end of checker.key-locator.hyper-relation!");
+ BOOST_THROW_EXCEPTION(Error("Expect the end of checker.key-locator.hyper-relation!"));
KeyLocatorChecker::Relation relation;
if (boost::iequals(hRelation, "equal"))
@@ -361,7 +361,8 @@
else if (boost::iequals(hRelation, "is-strict-prefix-of"))
relation = KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF;
else
- throw Error("Unsupported checker.key-locator.hyper-relation.h-relation: " + hRelation);
+ BOOST_THROW_EXCEPTION(Error("Unsupported checker.key-locator.hyper-relation.h-relation: "
+ + hRelation));
try
{
@@ -372,11 +373,11 @@
}
catch (Regex::Error& e)
{
- throw Error("Invalid regex for key-locator.hyper-relation");
+ BOOST_THROW_EXCEPTION(Error("Invalid regex for key-locator.hyper-relation"));
}
}
else
- throw Error("Unsupported checker.key-locator");
+ BOOST_THROW_EXCEPTION(Error("Unsupported checker.key-locator"));
}
};