summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/DescriptorHelper.cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2017-09-20 11:05:13 +0200
committerJose <jose@zeroc.com>2017-09-20 11:05:13 +0200
commit7f0816001e085f482f8f9a34b7f8e06435907510 (patch)
tree46807f18b840e1c9816cd9b4aac001c8078d8bce /cpp/src/IceGrid/DescriptorHelper.cpp
parentFixed Ice/acm Java7 build failure (diff)
downloadice-7f0816001e085f482f8f9a34b7f8e06435907510.tar.bz2
ice-7f0816001e085f482f8f9a34b7f8e06435907510.tar.xz
ice-7f0816001e085f482f8f9a34b7f8e06435907510.zip
Clean C++ exception code to only throw exception types
- Update C++ code to only throw types derived from C++ exception - Update C++ code to use one-shot constructors to create the exceptions Fix bug ICE-7892
Diffstat (limited to 'cpp/src/IceGrid/DescriptorHelper.cpp')
-rw-r--r--cpp/src/IceGrid/DescriptorHelper.cpp110
1 files changed, 36 insertions, 74 deletions
diff --git a/cpp/src/IceGrid/DescriptorHelper.cpp b/cpp/src/IceGrid/DescriptorHelper.cpp
index 6dd1ba686fd..3cfa5c7a248 100644
--- a/cpp/src/IceGrid/DescriptorHelper.cpp
+++ b/cpp/src/IceGrid/DescriptorHelper.cpp
@@ -535,44 +535,28 @@ Resolver::Resolver(const InternalNodeInfoPtr& info, const Ice::CommunicatorPtr&
string
Resolver::operator()(const string& value, const string& name, bool allowEmpty) const
{
+ string val;
try
{
- string val;
- try
- {
- val = substitute(value, true, true);
- }
- catch(const string& reason)
- {
- throw "invalid variable `" + value + "':\n " + reason;
- }
- catch(const char* reason)
- {
- throw "invalid variable `" + value + "':\n " + reason;
- }
-
- if(!allowEmpty)
- {
- if(value.empty())
- {
- throw "empty string";
- }
- else if(val.empty())
- {
- throw "the value of `" + value + "' is an empty string";
- }
- }
- return val;
+ val = substitute(value, true, true);
}
- catch(const string& reason)
+ catch(const std::exception& ex)
{
- exception("invalid value for attribute `" + name + "':\n" + reason);
+ exception("invalid value for attribute `" + name + "':\ninvalid variable `" + value + "':\n " + ex.what());
}
- catch(const char* reason)
+
+ if(!allowEmpty)
{
- exception("invalid value for attribute `" + name + "':\n" + reason);
+ if(value.empty())
+ {
+ exception("invalid value for attribute `" + name + "':\nempty string");
+ }
+ else if(val.empty())
+ {
+ exception("invalid value for attribute `" + name + "':\nthe value of `" + value + "' is an empty string");
+ }
}
- return ""; // To prevent compiler warning.
+ return val;
}
Ice::StringSeq
@@ -716,42 +700,26 @@ Resolver::asFloat(const string& value, const string& name) const
string
Resolver::asId(const string& value, const string& name, bool allowEmpty) const
{
- try
+ if(!allowEmpty && value.empty())
{
- if(!allowEmpty && value.empty())
- {
- throw "empty string";
- }
-
- string val;
- try
- {
- val = substitute(value, true, false);
- }
- catch(const string& reason)
- {
- throw "invalid variable `" + value + "':\n" + reason;
- }
- catch(const char* reason)
- {
- throw "invalid variable `" + value + "':\n" + reason;
- }
+ exception("invalid value for attribute `" + name + "':\nempty string");
+ }
- if(!allowEmpty && val.empty())
- {
- throw "the value of `" + value + "' is an empty string";
- }
- return val;
+ string val;
+ try
+ {
+ val = substitute(value, true, false);
}
- catch(const string& reason)
+ catch(const std::exception& ex)
{
- exception("invalid value for attribute `" + name + "':\n" + reason);
+ exception("invalid value for attribute `" + name + "':\ninvalid variable `" + value + "':\n" + ex.what());
}
- catch(const char* reason)
+
+ if(!allowEmpty && val.empty())
{
- exception("invalid value for attribute `" + name + "':\n" + reason);
+ exception("invalid value for attribute `" + name + "':\nthe value of `" + value + "' is an empty string");
}
- return ""; // To prevent compiler warning.
+ return val;
}
void
@@ -768,13 +736,9 @@ Resolver::setContext(const string& context)
{
_context = substitute(context, true, true);
}
- catch(const string& reason)
+ catch(const std::exception& ex)
{
- exception(reason);
- }
- catch(const char* reason)
- {
- exception(reason);
+ exception(ex.what());
}
}
@@ -943,7 +907,7 @@ Resolver::substitute(const string& v, bool useParams, bool useIgnored) const
end = value.find("}", beg);
if(end == string::npos)
{
- throw "malformed variable name `" + value + "'";
+ throw invalid_argument("malformed variable name `" + value + "'");
}
//
@@ -965,7 +929,7 @@ Resolver::substitute(const string& v, bool useParams, bool useIgnored) const
}
else
{
- throw "use of the `" + name + "' variable is now allowed here";
+ throw invalid_argument("use of the `" + name + "' variable is now allowed here");
}
}
@@ -995,7 +959,7 @@ Resolver::getVariable(const string& name, bool checkParams, bool& param) const
checkDeprecated(name);
if(p->second.empty())
{
- throw "undefined variable `" + name + "'";
+ throw invalid_argument("undefined variable `" + name + "'");
}
return p->second;
}
@@ -1009,13 +973,11 @@ Resolver::getVariable(const string& name, bool checkParams, bool& param) const
}
}
p = _variables.find(name);
- if(p != _variables.end())
+ if(p == _variables.end())
{
- return p->second;
+ throw invalid_argument("undefined variable `" + name + "'");
}
-
- throw "undefined variable `" + name + "'";
- return ""; // To keep the compiler happy.
+ return p->second;
}
PropertyDescriptorSeq