summaryrefslogtreecommitdiff
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
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
-rw-r--r--cpp/src/Glacier2/ClientBlobject.cpp11
-rw-r--r--cpp/src/Glacier2/ProxyVerifier.cpp50
-rw-r--r--cpp/src/Glacier2/SessionRouterI.cpp12
-rw-r--r--cpp/src/Ice/ConnectionI.cpp20
-rw-r--r--cpp/src/Ice/DefaultsAndOverrides.cpp10
-rw-r--r--cpp/src/Ice/EndpointFactoryManager.cpp18
-rw-r--r--cpp/src/Ice/IPEndpointI.cpp43
-rw-r--r--cpp/src/Ice/Initialize.cpp24
-rw-r--r--cpp/src/Ice/Instance.cpp34
-rw-r--r--cpp/src/Ice/LocatorInfo.cpp11
-rw-r--r--cpp/src/Ice/MetricsAdminI.cpp7
-rwxr-xr-xcpp/src/Ice/Network.cpp234
-rw-r--r--cpp/src/Ice/Object.cpp4
-rw-r--r--cpp/src/Ice/ObjectAdapterI.cpp27
-rw-r--r--cpp/src/Ice/OpaqueEndpointI.cpp57
-rw-r--r--cpp/src/Ice/PluginManagerI.cpp43
-rw-r--r--cpp/src/Ice/PropertiesI.cpp16
-rw-r--r--cpp/src/Ice/Protocol.cpp16
-rw-r--r--cpp/src/Ice/ReferenceFactory.cpp133
-rw-r--r--cpp/src/Ice/Selector.cpp28
-rw-r--r--cpp/src/Ice/ServantManager.cpp44
-rw-r--r--cpp/src/Ice/Service.cpp48
-rwxr-xr-xcpp/src/Ice/StreamSocket.cpp64
-rwxr-xr-xcpp/src/Ice/TcpAcceptor.cpp16
-rw-r--r--cpp/src/Ice/TcpEndpointI.cpp15
-rw-r--r--cpp/src/Ice/UdpEndpointI.cpp42
-rwxr-xr-xcpp/src/Ice/UdpTransceiver.cpp52
-rw-r--r--cpp/src/Ice/ValueFactoryManagerI.cpp5
-rw-r--r--cpp/src/Ice/WSEndpoint.cpp5
-rw-r--r--cpp/src/Ice/WSTransceiver.cpp8
-rw-r--r--cpp/src/Ice/ios/StreamEndpointI.cpp15
-rw-r--r--cpp/src/Ice/ios/StreamTransceiver.cpp31
-rw-r--r--cpp/src/IceBT/AcceptorI.cpp22
-rw-r--r--cpp/src/IceBT/ConnectorI.cpp4
-rw-r--r--cpp/src/IceBT/EndpointI.cpp58
-rw-r--r--cpp/src/IceBT/StreamSocket.cpp24
-rw-r--r--cpp/src/IceBT/Util.cpp8
-rw-r--r--cpp/src/IceBox/ServiceManagerI.cpp40
-rw-r--r--cpp/src/IceGrid/Activator.cpp75
-rw-r--r--cpp/src/IceGrid/AdminI.cpp32
-rw-r--r--cpp/src/IceGrid/AdminSessionI.cpp36
-rw-r--r--cpp/src/IceGrid/Database.cpp75
-rw-r--r--cpp/src/IceGrid/DescriptorBuilder.cpp58
-rw-r--r--cpp/src/IceGrid/DescriptorHelper.cpp110
-rw-r--r--cpp/src/IceGrid/DescriptorParser.cpp18
-rw-r--r--cpp/src/IceGrid/FileUserAccountMapperI.cpp2
-rw-r--r--cpp/src/IceGrid/IceGridNode.cpp36
-rw-r--r--cpp/src/IceGrid/InternalRegistryI.cpp8
-rw-r--r--cpp/src/IceGrid/NodeCache.cpp4
-rw-r--r--cpp/src/IceGrid/NodeI.cpp40
-rw-r--r--cpp/src/IceGrid/Parser.cpp2
-rw-r--r--cpp/src/IceGrid/PlatformInfo.cpp6
-rw-r--r--cpp/src/IceGrid/RegistryI.cpp116
-rw-r--r--cpp/src/IceGrid/ReplicaCache.cpp4
-rw-r--r--cpp/src/IceGrid/ServerAdapterI.cpp4
-rw-r--r--cpp/src/IceGrid/ServerCache.cpp4
-rw-r--r--cpp/src/IceGrid/ServerI.cpp121
-rw-r--r--cpp/src/IceGrid/SessionI.cpp12
-rw-r--r--cpp/src/IceGrid/Topics.cpp6
-rw-r--r--cpp/src/IcePatch2/Calc.cpp18
-rw-r--r--cpp/src/IcePatch2/Client.cpp4
-rw-r--r--cpp/src/IcePatch2/Server.cpp11
-rw-r--r--cpp/src/IcePatch2Lib/ClientUtil.cpp40
-rw-r--r--cpp/src/IcePatch2Lib/Util.cpp115
-rw-r--r--cpp/src/IceSSL/AcceptorI.cpp4
-rw-r--r--cpp/src/IceSSL/ConnectorI.cpp4
-rw-r--r--cpp/src/IceSSL/OpenSSLTransceiverI.cpp85
-rw-r--r--cpp/src/IceSSL/SChannelTransceiverI.cpp44
-rw-r--r--cpp/src/IceSSL/SSLEngine.cpp21
-rw-r--r--cpp/src/IceSSL/SecureTransportUtil.cpp15
-rw-r--r--cpp/src/IceSSL/TrustManager.cpp7
-rw-r--r--cpp/src/IceStorm/Service.cpp17
-rw-r--r--cpp/src/IceStorm/TopicI.cpp8
-rw-r--r--cpp/src/IceStorm/TopicManagerI.cpp8
-rw-r--r--cpp/src/IceStorm/TransientTopicI.cpp10
-rw-r--r--cpp/src/IceStorm/TransientTopicManagerI.cpp8
-rw-r--r--cpp/src/IceUtil/FileUtil.cpp8
-rw-r--r--cpp/src/IceUtil/UUID.cpp4
-rw-r--r--cpp/src/Slice/Python.cpp20
-rw-r--r--cpp/src/iceserviceinstall/Install.cpp9
-rw-r--r--cpp/src/iceserviceinstall/ServiceInstaller.cpp180
-rw-r--r--cpp/src/slice2html/Gen.cpp3
-rw-r--r--cpp/test/IceSSL/configuration/AllTests.cpp4
83 files changed, 903 insertions, 1812 deletions
diff --git a/cpp/src/Glacier2/ClientBlobject.cpp b/cpp/src/Glacier2/ClientBlobject.cpp
index c332c546ba2..e251a25dfe4 100644
--- a/cpp/src/Glacier2/ClientBlobject.cpp
+++ b/cpp/src/Glacier2/ClientBlobject.cpp
@@ -80,18 +80,13 @@ Glacier2::ClientBlobject::ice_invoke_async(const Ice::AMD_Object_ice_invokePtr&
ObjectPrx proxy = _routingTable->get(current.id);
if(!proxy)
{
- ObjectNotExistException ex(__FILE__, __LINE__);
-
//
// We use a special operation name indicate to the client that
// the proxy for the Ice object has not been found in our
// routing table. This can happen if the proxy was evicted
// from the routing table.
//
- ex.id = current.id;
- ex.facet = current.facet;
- ex.operation = "ice_add_proxy";
- throw ex;
+ throw ObjectNotExistException(__FILE__, __LINE__, current.id, current.facet, "ice_add_proxy");
}
string adapterId = proxy->ice_getAdapterId();
@@ -123,9 +118,7 @@ Glacier2::ClientBlobject::ice_invoke_async(const Ice::AMD_Object_ice_invokePtr&
out << "identity: " << _instance->communicator()->identityToString(current.id);
}
- ObjectNotExistException ex(__FILE__, __LINE__);
- ex.id = current.id;
- throw ex;
+ throw ObjectNotExistException(__FILE__, __LINE__, current.id, "", "");
}
invoke(proxy, amdCB, inParams, current);
}
diff --git a/cpp/src/Glacier2/ProxyVerifier.cpp b/cpp/src/Glacier2/ProxyVerifier.cpp
index 9df5d0be407..302ec125649 100644
--- a/cpp/src/Glacier2/ProxyVerifier.cpp
+++ b/cpp/src/Glacier2/ProxyVerifier.cpp
@@ -49,7 +49,7 @@ parseGroup(const string& parameter, vector<int>& validPorts, vector<Range>& rang
int value;
if(!(istr >> value))
{
- throw string("expected number");
+ throw invalid_argument("expected number");
}
ws(istr);
if(!istr.eof())
@@ -68,11 +68,11 @@ parseGroup(const string& parameter, vector<int>& validPorts, vector<Range>& rang
ws(istr);
if(istr.eof())
{
- throw string("Unterminated range");
+ throw invalid_argument("Unterminated range");
}
if(!(istr >> value))
{
- throw string("expected number");
+ throw invalid_argument("expected number");
}
r.end = value;
ws(istr);
@@ -81,14 +81,14 @@ parseGroup(const string& parameter, vector<int>& validPorts, vector<Range>& rang
istr >> c;
if(c != ',')
{
- throw string("expected comma separator");
+ throw invalid_argument("expected comma separator");
}
}
ranges.push_back(r);
}
else if(!istr.eof())
{
- throw string("unexpected trailing character");
+ throw invalid_argument("unexpected trailing character");
}
}
}
@@ -679,7 +679,7 @@ parseProperty(const Ice::CommunicatorPtr& communicator, const string& property,
string::size_type closeBracket = port.find(']', openBracket);
if(closeBracket == string::npos)
{
- throw string("unclosed group");
+ throw invalid_argument("unclosed group");
}
port = port.substr(openBracket, closeBracket-openBracket);
}
@@ -701,7 +701,7 @@ parseProperty(const Ice::CommunicatorPtr& communicator, const string& property,
if(current == addr.size())
{
- throw string("expected address information before ':'");
+ throw invalid_argument("expected address information before ':'");
}
//
@@ -735,7 +735,7 @@ parseProperty(const Ice::CommunicatorPtr& communicator, const string& property,
{
if(inGroup)
{
- throw string("wildcards not permitted in groups");
+ throw invalid_argument("wildcards not permitted in groups");
}
//
// current == mark when the wildcard is at the head of a
@@ -763,12 +763,12 @@ parseProperty(const Ice::CommunicatorPtr& communicator, const string& property,
{
if(!inGroup)
{
- throw string("group close without group start");
+ throw invalid_argument("group close without group start");
}
inGroup = false;
if(mark == current)
{
- throw string("empty group");
+ throw invalid_argument("empty group");
}
string group = addr.substr(mark, current - mark);
vector<int> numbers;
@@ -783,7 +783,7 @@ parseProperty(const Ice::CommunicatorPtr& communicator, const string& property,
if(inGroup)
{
- throw string("unclosed group");
+ throw invalid_argument("unclosed group");
}
if(mark != current)
{
@@ -834,11 +834,11 @@ public:
istringstream s(count);
if(!(s >> _count) || !s.eof())
{
- throw string("Error parsing ProxySizeMax property");
+ throw invalid_argument("Error parsing ProxySizeMax property");
}
if(_count <= 0)
{
- throw string("ProxySizeMax must be greater than 1");
+ throw invalid_argument("ProxySizeMax must be greater than 1");
}
}
@@ -879,11 +879,11 @@ Glacier2::ProxyVerifier::ProxyVerifier(const CommunicatorPtr& communicator):
{
Glacier2::parseProperty(communicator, s, _acceptRules, _traceLevel);
}
- catch(const string& msg)
+ catch(const exception& ex)
{
- InitializationException ex(__FILE__, __LINE__);
- ex.reason = "invalid `Glacier2.Filter.Address.Accept' property:\n" + msg;
- throw ex;
+ ostringstream os;
+ os << "invalid `Glacier2.Filter.Address.Accept' property:\n" << ex.what();
+ throw InitializationException(__FILE__, __LINE__, os.str());
}
}
@@ -894,11 +894,11 @@ Glacier2::ProxyVerifier::ProxyVerifier(const CommunicatorPtr& communicator):
{
Glacier2::parseProperty(communicator, s, _rejectRules, _traceLevel);
}
- catch(const string& msg)
+ catch(const exception& ex)
{
- InitializationException ex(__FILE__, __LINE__);
- ex.reason = "invalid `Glacier2.Filter.Address.Reject' property:\n" + msg;
- throw ex;
+ ostringstream os;
+ os << "invalid `Glacier2.Filter.Address.Reject' property:\n" << ex.what();
+ throw InitializationException(__FILE__, __LINE__, os.str());
}
}
@@ -910,11 +910,11 @@ Glacier2::ProxyVerifier::ProxyVerifier(const CommunicatorPtr& communicator):
_rejectRules.push_back(new ProxyLengthRule(communicator, s, _traceLevel));
}
- catch(const string& msg)
+ catch(const exception& ex)
{
- InitializationException ex(__FILE__, __LINE__);
- ex.reason = "invalid `Glacier2.Filter.ProxySizeMax' property:\n" + msg;
- throw ex;
+ ostringstream os;
+ os << "invalid `Glacier2.Filter.ProxySizeMax' property:\n" << ex.what();
+ throw InitializationException(__FILE__, __LINE__, os.str());
}
}
}
diff --git a/cpp/src/Glacier2/SessionRouterI.cpp b/cpp/src/Glacier2/SessionRouterI.cpp
index 0172d4ee35f..e485f76c921 100644
--- a/cpp/src/Glacier2/SessionRouterI.cpp
+++ b/cpp/src/Glacier2/SessionRouterI.cpp
@@ -1177,9 +1177,7 @@ SessionRouterI::startCreateSession(const CreateSessionPtr& cb, const ConnectionP
if(_destroy)
{
- CannotCreateSessionException exc;
- exc.reason = "router is shutting down";
- throw exc;
+ throw CannotCreateSessionException("router is shutting down");
}
//
@@ -1199,9 +1197,7 @@ SessionRouterI::startCreateSession(const CreateSessionPtr& cb, const ConnectionP
if(p != _routersByConnection.end())
{
- CannotCreateSessionException exc;
- exc.reason = "session exists";
- throw exc;
+ throw CannotCreateSessionException("session exists");
}
}
@@ -1248,9 +1244,7 @@ SessionRouterI::finishCreateSession(const ConnectionPtr& connection, const Route
{
router->destroy(_sessionDestroyCallback);
- CannotCreateSessionException exc;
- exc.reason = "router is shutting down";
- throw exc;
+ throw CannotCreateSessionException("router is shutting down");
}
_routersByConnectionHint = _routersByConnection.insert(
diff --git a/cpp/src/Ice/ConnectionI.cpp b/cpp/src/Ice/ConnectionI.cpp
index dbd92516cad..9b0a9f4f304 100644
--- a/cpp/src/Ice/ConnectionI.cpp
+++ b/cpp/src/Ice/ConnectionI.cpp
@@ -1651,9 +1651,7 @@ Ice::ConnectionI::message(ThreadPoolCurrent& current)
_readStream.readBlob(m, static_cast<Int>(sizeof(magic)));
if(m[0] != magic[0] || m[1] != magic[1] || m[2] != magic[2] || m[3] != magic[3])
{
- BadMagicException ex(__FILE__, __LINE__);
- ex.badMagic = Ice::ByteSeq(&m[0], &m[0] + sizeof(magic));
- throw ex;
+ throw BadMagicException(__FILE__, __LINE__, "", Ice::ByteSeq(&m[0], &m[0] + sizeof(magic)));
}
ProtocolVersion pv;
_readStream.read(pv);
@@ -2722,9 +2720,7 @@ Ice::ConnectionI::validate(SocketOperation operation)
_readStream.read(m[3]);
if(m[0] != magic[0] || m[1] != magic[1] || m[2] != magic[2] || m[3] != magic[3])
{
- BadMagicException ex(__FILE__, __LINE__);
- ex.badMagic = Ice::ByteSeq(&m[0], &m[0] + sizeof(magic));
- throw ex;
+ throw BadMagicException(__FILE__, __LINE__, "", Ice::ByteSeq(&m[0], &m[0] + sizeof(magic)));
}
ProtocolVersion pv;
_readStream.read(pv);
@@ -3138,9 +3134,7 @@ Ice::ConnectionI::doCompress(OutputStream& uncompressed, OutputStream& compresse
_compressionLevel, 0, 0);
if(bzError != BZ_OK)
{
- CompressionException ex(__FILE__, __LINE__);
- ex.reason = "BZ2_bzBuffToBuffCompress failed" + getBZ2Error(bzError);
- throw ex;
+ throw CompressionException(__FILE__, __LINE__, "BZ2_bzBuffToBuffCompress failed" + getBZ2Error(bzError));
}
compressed.b.resize(headerSize + sizeof(Int) + compressedLen);
@@ -3201,9 +3195,7 @@ Ice::ConnectionI::doUncompress(InputStream& compressed, InputStream& uncompresse
0, 0);
if(bzError != BZ_OK)
{
- CompressionException ex(__FILE__, __LINE__);
- ex.reason = "BZ2_bzBuffToBuffCompress failed" + getBZ2Error(bzError);
- throw ex;
+ throw CompressionException(__FILE__, __LINE__, "BZ2_bzBuffToBuffCompress failed" + getBZ2Error(bzError));
}
copy(compressed.b.begin(), compressed.b.begin() + headerSize, uncompressed.b.begin());
@@ -3253,9 +3245,7 @@ Ice::ConnectionI::parseMessage(InputStream& stream, Int& invokeNum, Int& request
doUncompress(stream, ustream);
stream.b.swap(ustream.b);
#else
- FeatureNotSupportedException ex(__FILE__, __LINE__);
- ex.unsupportedFeature = "Cannot uncompress compressed message";
- throw ex;
+ throw FeatureNotSupportedException(__FILE__, __LINE__, "Cannot uncompress compressed message");
#endif
}
stream.i = stream.b.begin() + headerSize;
diff --git a/cpp/src/Ice/DefaultsAndOverrides.cpp b/cpp/src/Ice/DefaultsAndOverrides.cpp
index 4e61890d373..3dd16c37412 100644
--- a/cpp/src/Ice/DefaultsAndOverrides.cpp
+++ b/cpp/src/Ice/DefaultsAndOverrides.cpp
@@ -43,9 +43,8 @@ IceInternal::DefaultsAndOverrides::DefaultsAndOverrides(const PropertiesPtr& pro
const_cast<Address&>(defaultSourceAddress) = getNumericAddress(value);
if(!isAddressValid(defaultSourceAddress))
{
- InitializationException ex(__FILE__, __LINE__);
- ex.reason = "invalid IP address set for Ice.Default.SourceAddress: `" + value + "'";
- throw ex;
+ throw InitializationException(__FILE__, __LINE__, "invalid IP address set for Ice.Default.SourceAddress: `" +
+ value + "'");
}
}
#endif
@@ -120,9 +119,8 @@ IceInternal::DefaultsAndOverrides::DefaultsAndOverrides(const PropertiesPtr& pro
}
else
{
- EndpointSelectionTypeParseException ex(__FILE__, __LINE__);
- ex.str = "illegal value `" + value + "'; expected `Random' or `Ordered'";
- throw ex;
+ throw EndpointSelectionTypeParseException(__FILE__, __LINE__, "illegal value `" + value +
+ "'; expected `Random' or `Ordered'");
}
const_cast<int&>(defaultTimeout) =
diff --git a/cpp/src/Ice/EndpointFactoryManager.cpp b/cpp/src/Ice/EndpointFactoryManager.cpp
index a2105da4274..f3672177b70 100644
--- a/cpp/src/Ice/EndpointFactoryManager.cpp
+++ b/cpp/src/Ice/EndpointFactoryManager.cpp
@@ -81,16 +81,12 @@ IceInternal::EndpointFactoryManager::create(const string& str, bool oaEndpoint)
bool b = IceUtilInternal::splitString(str, " \t\n\r", v);
if(!b)
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "mismatched quote";
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "mismatched quote");
}
if(v.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "value has no non-whitespace characters";
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "value has no non-whitespace characters");
}
string protocol = v.front();
@@ -123,9 +119,8 @@ IceInternal::EndpointFactoryManager::create(const string& str, bool oaEndpoint)
EndpointIPtr e = factory->create(v, oaEndpoint);
if(!v.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "unrecognized argument `" + v.front() + "' in endpoint `" + str + "'";
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "unrecognized argument `" + v.front() +
+ "' in endpoint `" + str + "'");
}
return e;
#else
@@ -153,9 +148,8 @@ IceInternal::EndpointFactoryManager::create(const string& str, bool oaEndpoint)
EndpointIPtr ue = ICE_MAKE_SHARED(OpaqueEndpointI, v);
if(!v.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "unrecognized argument `" + v.front() + "' in endpoint `" + str + "'";
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "unrecognized argument `" + v.front() + "' in endpoint `" +
+ str + "'");
}
factory = get(ue->type());
if(factory)
diff --git a/cpp/src/Ice/IPEndpointI.cpp b/cpp/src/Ice/IPEndpointI.cpp
index 26d710898f0..d13c689d43a 100644
--- a/cpp/src/Ice/IPEndpointI.cpp
+++ b/cpp/src/Ice/IPEndpointI.cpp
@@ -426,9 +426,8 @@ IceInternal::IPEndpointI::initWithOptions(vector<string>& args, bool oaEndpoint)
}
else
{
- Ice::EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "`-h *' not valid for proxy endpoint `" + toString() + "'";
- throw ex;
+ throw Ice::EndpointParseException(__FILE__, __LINE__, "`-h *' not valid for proxy endpoint `" + toString() +
+ "'");
}
}
@@ -436,9 +435,9 @@ IceInternal::IPEndpointI::initWithOptions(vector<string>& args, bool oaEndpoint)
{
if(oaEndpoint)
{
- Ice::EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "`--sourceAddress' not valid for object adapter endpoint `" + toString() + "'";
- throw ex;
+ throw Ice::EndpointParseException(__FILE__, __LINE__,
+ "`--sourceAddress' not valid for object adapter endpoint `" + toString() +
+ "'");
}
}
else if(!oaEndpoint)
@@ -454,9 +453,8 @@ IceInternal::IPEndpointI::checkOption(const string& option, const string& argume
{
if(argument.empty())
{
- Ice::EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -h option in endpoint " + endpoint;
- throw ex;
+ throw Ice::EndpointParseException(__FILE__, __LINE__, "no argument provided for -h option in endpoint " +
+ endpoint);
}
const_cast<string&>(_host) = argument;
}
@@ -464,39 +462,36 @@ IceInternal::IPEndpointI::checkOption(const string& option, const string& argume
{
if(argument.empty())
{
- Ice::EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -p option in endpoint " + endpoint;
- throw ex;
+ throw Ice::EndpointParseException(__FILE__, __LINE__, "no argument provided for -p option in endpoint " +
+ endpoint);
}
istringstream p(argument);
if(!(p >> const_cast<Ice::Int&>(_port)) || !p.eof())
{
- Ice::EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid port value `" + argument + "' in endpoint " + endpoint;
- throw ex;
+ throw Ice::EndpointParseException(__FILE__, __LINE__, "invalid port value `" + argument + "' in endpoint " +
+ endpoint);
}
else if(_port < 0 || _port > 65535)
{
- Ice::EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "port value `" + argument + "' out of range in endpoint " + endpoint;
- throw ex;
+ throw Ice::EndpointParseException(__FILE__, __LINE__, "port value `" + argument +
+ "' out of range in endpoint " + endpoint);
}
}
else if(option == "--sourceAddress")
{
if(argument.empty())
{
- Ice::EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for --sourceAddress option in endpoint " + endpoint;
- throw ex;
+ throw Ice::EndpointParseException(__FILE__, __LINE__,
+ "no argument provided for --sourceAddress option in endpoint " +
+ endpoint);
}
#ifndef ICE_OS_UWP
const_cast<Address&>(_sourceAddr) = getNumericAddress(argument);
if(!isAddressValid(_sourceAddr))
{
- Ice::EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid IP address provided for --sourceAddress option in endpoint " + endpoint;
- throw ex;
+ throw Ice::EndpointParseException(__FILE__, __LINE__,
+ "invalid IP address provided for --sourceAddress option in endpoint " +
+ endpoint);
}
#endif
}
diff --git a/cpp/src/Ice/Initialize.cpp b/cpp/src/Ice/Initialize.cpp
index cc1997f2c65..eab2d4943fd 100644
--- a/cpp/src/Ice/Initialize.cpp
+++ b/cpp/src/Ice/Initialize.cpp
@@ -599,9 +599,7 @@ Ice::stringToIdentity(const string& s)
//
// Extra unescaped slash found.
//
- IdentityParseException ex(__FILE__, __LINE__);
- ex.str = "unescaped '/' in identity `" + s + "'";
- throw ex;
+ throw IdentityParseException(__FILE__, __LINE__, "unescaped '/' in identity `" + s + "'");
}
}
pos++;
@@ -613,11 +611,9 @@ Ice::stringToIdentity(const string& s)
{
ident.name = unescapeString(s, 0, s.size(), "/");
}
- catch(const IceUtil::IllegalArgumentException& e)
+ catch(const IceUtil::IllegalArgumentException& ex)
{
- IdentityParseException ex(__FILE__, __LINE__);
- ex.str = "invalid identity name `" + s + "': " + e.reason();
- throw ex;
+ throw IdentityParseException(__FILE__, __LINE__, "invalid identity name `" + s + "': " + ex.reason());
}
}
else
@@ -626,11 +622,10 @@ Ice::stringToIdentity(const string& s)
{
ident.category = unescapeString(s, 0, slash, "/");
}
- catch(const IceUtil::IllegalArgumentException& e)
+ catch(const IceUtil::IllegalArgumentException& ex)
{
- IdentityParseException ex(__FILE__, __LINE__);
- ex.str = "invalid category in identity `" + s + "': " + e.reason();
- throw ex;
+ throw IdentityParseException(__FILE__, __LINE__, "invalid category in identity `" + s + "': " +
+ ex.reason());
}
if(slash + 1 < s.size())
@@ -639,11 +634,10 @@ Ice::stringToIdentity(const string& s)
{
ident.name = unescapeString(s, slash + 1, s.size(), "/");
}
- catch(const IceUtil::IllegalArgumentException& e)
+ catch(const IceUtil::IllegalArgumentException& ex)
{
- IdentityParseException ex(__FILE__, __LINE__);
- ex.str = "invalid name in identity `" + s + "': " + e.reason();
- throw ex;
+ throw IdentityParseException(__FILE__, __LINE__, "invalid name in identity `" + s + "': " +
+ ex.reason());
}
}
}
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp
index 87d15201c98..2e6ea32af08 100644
--- a/cpp/src/Ice/Instance.cpp
+++ b/cpp/src/Ice/Instance.cpp
@@ -980,10 +980,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Initi
FILE* file = IceUtilInternal::freopen(stdOutFilename, "a", stdout);
if(file == 0)
{
- FileException ex(__FILE__, __LINE__);
- ex.path = stdOutFilename;
- ex.error = getSystemErrno();
- throw ex;
+ throw FileException(__FILE__, __LINE__, getSystemErrno(), stdOutFilename);
}
}
@@ -992,10 +989,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Initi
FILE* file = IceUtilInternal::freopen(stdErrFilename, "a", stderr);
if(file == 0)
{
- FileException ex(__FILE__, __LINE__);
- ex.path = stdErrFilename;
- ex.error = getSystemErrno();
- throw ex;
+ throw FileException(__FILE__, __LINE__, getSystemErrno(), stdErrFilename);
}
}
@@ -1030,36 +1024,26 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Initi
}
if(err != 0)
{
- Ice::SyscallException ex(__FILE__, __LINE__);
- ex.error = err;
- throw ex;
+ throw Ice::SyscallException(__FILE__, __LINE__, err);
}
else if(pw == 0)
{
- InitializationException ex(__FILE__, __LINE__);
- ex.reason ="unknown user account `" + newUser + "'";
- throw ex;
+ throw InitializationException(__FILE__, __LINE__, "unknown user account `" + newUser + "'");
}
if(setgid(pw->pw_gid) == -1)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
if(initgroups(pw->pw_name, pw->pw_gid) == -1)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
if(setuid(pw->pw_uid) == -1)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
}
#endif
@@ -1073,9 +1057,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Initi
WSADATA data;
if(WSAStartup(version, &data) != 0)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
#endif
diff --git a/cpp/src/Ice/LocatorInfo.cpp b/cpp/src/Ice/LocatorInfo.cpp
index fc17b90c4e3..d0ab095c95a 100644
--- a/cpp/src/Ice/LocatorInfo.cpp
+++ b/cpp/src/Ice/LocatorInfo.cpp
@@ -673,10 +673,7 @@ IceInternal::LocatorInfo::getEndpointsException(const ReferencePtr& ref, const I
out << "adapter = " << ref->getAdapterId();
}
- NotRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = "object adapter";
- ex.id = ref->getAdapterId();
- throw ex;
+ throw NotRegisteredException(__FILE__, __LINE__, "object adapter", ref->getAdapterId());
}
catch(const ObjectNotFoundException&)
{
@@ -689,10 +686,8 @@ IceInternal::LocatorInfo::getEndpointsException(const ReferencePtr& ref, const I
ref->getInstance()->toStringMode());
}
- NotRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = "object";
- ex.id = Ice::identityToString(ref->getIdentity(), ref->getInstance()->toStringMode());
- throw ex;
+ throw NotRegisteredException(__FILE__, __LINE__, "object",
+ Ice::identityToString(ref->getIdentity(), ref->getInstance()->toStringMode()));
}
catch(const NotRegisteredException&)
{
diff --git a/cpp/src/Ice/MetricsAdminI.cpp b/cpp/src/Ice/MetricsAdminI.cpp
index dfb6b513858..8c67035a42d 100644
--- a/cpp/src/Ice/MetricsAdminI.cpp
+++ b/cpp/src/Ice/MetricsAdminI.cpp
@@ -84,7 +84,7 @@ parseRule(const PropertiesPtr& properties, const string& name)
}
catch(const std::exception&)
{
- throw "invalid regular expression `" + p->second + "' for `" + p->first + "'";
+ throw invalid_argument("invalid regular expression `" + p->second + "' for `" + p->first + "'");
}
}
return regexps;
@@ -315,11 +315,6 @@ MetricsViewI::addOrUpdateMap(const PropertiesPtr& properties, const string& mapN
::Ice::Warning warn(logger);
warn << "unexpected exception while creating metrics map:\n" << ex;
}
- catch(const string& msg)
- {
- ::Ice::Warning warn(logger);
- warn << msg;
- }
return true;
}
diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp
index a4b6cc10c28..09508a02737 100755
--- a/cpp/src/Ice/Network.cpp
+++ b/cpp/src/Ice/Network.cpp
@@ -153,9 +153,7 @@ setTcpNoDelay(SOCKET fd)
if(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>(&flag), int(sizeof(int))) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
@@ -166,9 +164,7 @@ setKeepAlive(SOCKET fd)
if(setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, reinterpret_cast<char*>(&flag), int(sizeof(int))) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
#endif
@@ -189,9 +185,7 @@ setTcpLoopbackFastPath(SOCKET fd)
if(LastError != WSAEOPNOTSUPP)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
}
@@ -233,9 +227,7 @@ createSocketImpl(bool udp, int family)
if(fd == INVALID_SOCKET)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
if(!udp)
@@ -325,9 +317,7 @@ getLocalAddresses(ProtocolSupport protocol, bool includeLoopback)
struct ifaddrs* ifap;
if(::getifaddrs(&ifap) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
struct ifaddrs* curr = ifap;
@@ -394,9 +384,7 @@ getLocalAddresses(ProtocolSupport protocol, bool includeLoopback)
{
free(ifc.ifc_buf);
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketError());
}
else if(ifc.ifc_len == old_ifc_len)
{
@@ -832,9 +820,7 @@ IceInternal::NativeInfo::completed(SocketOperation operation)
{
if(!PostQueuedCompletionStatus(_handle, 0, _key, getAsyncInfo(operation)))
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = GetLastError();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, GetLastError());
}
}
@@ -1059,10 +1045,7 @@ IceInternal::getAddresses(const string& host, int port, ProtocolSupport, Ice::En
}
catch(Platform::Exception^ pex)
{
- DNSException ex(__FILE__, __LINE__);
- ex.error = (int)SocketError::GetStatus(pex->HResult);
- ex.host = host;
- throw ex;
+ throw DNSException(__FILE__, __LINE__, (int)SocketError::GetStatus(pex->HResult), host);
}
}
@@ -1143,10 +1126,7 @@ IceInternal::getAddresses(const string& host, int port, ProtocolSupport protocol
}
else if(rs != 0)
{
- DNSException ex(__FILE__, __LINE__);
- ex.error = rs;
- ex.host = host;
- throw ex;
+ throw DNSException(__FILE__, __LINE__, rs, host);
}
for(struct addrinfo* p = info; p != ICE_NULLPTR; p = p->ai_next)
@@ -1180,9 +1160,7 @@ IceInternal::getAddresses(const string& host, int port, ProtocolSupport protocol
if(result.empty())
{
- DNSException ex(__FILE__, __LINE__);
- ex.host = host;
- throw ex;
+ throw DNSException(__FILE__, __LINE__, 0, host);
}
sortAddresses(result, protocol, selType, preferIPv6);
return result;
@@ -1376,9 +1354,7 @@ IceInternal::createServerSocket(bool udp, const Address& addr, ProtocolSupport p
}
#endif
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
return fd;
@@ -1430,9 +1406,7 @@ IceInternal::closeSocket(SOCKET fd)
int error = WSAGetLastError();
if(closesocket(fd) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
WSASetLastError(error);
#else
@@ -1449,9 +1423,7 @@ IceInternal::closeSocket(SOCKET fd)
if(close(fd) == SOCKET_ERROR)
# endif
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
errno = error;
#endif
@@ -1472,9 +1444,7 @@ IceInternal::fdToLocalAddress(SOCKET fd, Address& addr)
socklen_t len = static_cast<socklen_t>(sizeof(sockaddr_storage));
if(getsockname(fd, &addr.sa, &len) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
#else
StreamSocket^ stream = dynamic_cast<StreamSocket^>(fd);
@@ -1505,9 +1475,7 @@ IceInternal::fdToRemoteAddress(SOCKET fd, Address& addr)
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
@@ -1958,9 +1926,7 @@ IceInternal::setBlock(SOCKET fd, bool block)
if(ioctlsocket(fd, FIONBIO, &arg) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = WSAGetLastError();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, WSAGetLastError());
}
}
else
@@ -1969,9 +1935,7 @@ IceInternal::setBlock(SOCKET fd, bool block)
if(ioctlsocket(fd, FIONBIO, &arg) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = WSAGetLastError();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, WSAGetLastError());
}
}
#else
@@ -1982,9 +1946,7 @@ IceInternal::setBlock(SOCKET fd, bool block)
if(fcntl(fd, F_SETFL, flags) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = errno;
- throw ex;
+ throw SocketException(__FILE__, __LINE__, errno);
}
}
else
@@ -1994,9 +1956,7 @@ IceInternal::setBlock(SOCKET fd, bool block)
if(fcntl(fd, F_SETFL, flags) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = errno;
- throw ex;
+ throw SocketException(__FILE__, __LINE__, errno);
}
}
#endif
@@ -2010,9 +1970,7 @@ IceInternal::setSendBufferSize(SOCKET fd, int sz)
if(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<char*>(&sz), int(sizeof(int))) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
#else
StreamSocket^ stream = dynamic_cast<StreamSocket^>(fd);
@@ -2033,9 +1991,7 @@ IceInternal::getSendBufferSize(SOCKET fd)
static_cast<unsigned int>(len) != sizeof(sz))
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
return sz;
#else
@@ -2060,9 +2016,7 @@ IceInternal::setRecvBufferSize(SOCKET fd, int sz)
if(setsockopt(fd, SOL_SOCKET, SO_RCVBUF, reinterpret_cast<char*>(&sz), int(sizeof(int))) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
#endif
@@ -2077,9 +2031,7 @@ IceInternal::getRecvBufferSize(SOCKET fd)
static_cast<unsigned int>(len) != sizeof(sz))
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
return sz;
#else
@@ -2118,9 +2070,7 @@ IceInternal::setMcastGroup(SOCKET fd, const Address& group, const string& intf)
if(rc == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
}
@@ -2190,9 +2140,7 @@ IceInternal::setMcastInterface(SOCKET fd, const string& intf, const Address& add
if(rc == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
#endif
@@ -2218,9 +2166,7 @@ IceInternal::setMcastTtl(SOCKET fd, int ttl, const Address& addr)
if(rc == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
#endif
@@ -2238,9 +2184,7 @@ IceInternal::setReuseAddress(SOCKET fd, bool reuse)
if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&flag), int(sizeof(int))) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
#endif
@@ -2365,9 +2309,7 @@ IceInternal::doBind(SOCKET fd, const Address& addr, const string&)
if(::bind(fd, &addr.sa, size) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
Address local;
@@ -2570,9 +2512,7 @@ repeatListen:
}
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
@@ -2603,21 +2543,15 @@ repeatConnect:
closeSocketNoThrow(fd);
if(connectionRefused())
{
- ConnectionRefusedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionRefusedException(__FILE__, __LINE__, getSocketErrno());
}
else if(connectFailed())
{
- ConnectFailedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectFailedException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
@@ -2633,9 +2567,7 @@ repeatConnect:
fdToLocalAddress(fd, localAddr);
if(compareAddress(addr, localAddr) == 0)
{
- ConnectionRefusedException ex(__FILE__, __LINE__);
- ex.error = 0; // No appropriate errno
- throw ex;
+ throw ConnectionRefusedException(__FILE__, __LINE__, 0); // No appropriate errno
}
}
catch(const LocalException&)
@@ -2668,9 +2600,7 @@ IceInternal::doFinishConnect(SOCKET fd)
socklen_t len = static_cast<socklen_t>(sizeof(int));
if(getsockopt(fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&val), &len) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
if(val > 0)
@@ -2682,21 +2612,15 @@ IceInternal::doFinishConnect(SOCKET fd)
#endif
if(connectionRefused())
{
- ConnectionRefusedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionRefusedException(__FILE__, __LINE__, getSocketErrno());
}
else if(connectFailed())
{
- ConnectFailedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectFailedException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
@@ -2711,9 +2635,7 @@ IceInternal::doFinishConnect(SOCKET fd)
Address remoteAddr;
if(fdToRemoteAddress(fd, remoteAddr) && compareAddress(remoteAddr, localAddr) == 0)
{
- ConnectionRefusedException ex(__FILE__, __LINE__);
- ex.error = 0; // No appropriate errno
- throw ex;
+ throw ConnectionRefusedException(__FILE__, __LINE__, 0); // No appropriate errno
}
#endif
}
@@ -2735,9 +2657,7 @@ repeatAccept:
goto repeatAccept;
}
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
setTcpNoDelay(ret);
@@ -2818,9 +2738,7 @@ IceInternal::createPipe(SOCKET fds[2])
if(::pipe(fds) != 0)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSocketErrno());
}
try
@@ -2855,16 +2773,12 @@ IceInternal::checkConnectErrorCode(const char* file, int line, HRESULT herr)
{
if(herr == E_ACCESSDENIED)
{
- SocketException ex(file, line);
- ex.error = static_cast<int>(herr);
- throw ex;
+ throw SocketException(file, line, static_cast<int>(herr));
}
SocketErrorStatus error = SocketError::GetStatus(herr);
if(error == SocketErrorStatus::ConnectionRefused)
{
- ConnectionRefusedException ex(file, line);
- ex.error = static_cast<int>(error);
- throw ex;
+ throw ConnectionRefusedException(file, line, static_cast<int>(error));
}
else if(error == SocketErrorStatus::NetworkDroppedConnectionOnReset ||
error == SocketErrorStatus::ConnectionTimedOut ||
@@ -2873,21 +2787,15 @@ IceInternal::checkConnectErrorCode(const char* file, int line, HRESULT herr)
error == SocketErrorStatus::ConnectionResetByPeer ||
error == SocketErrorStatus::SoftwareCausedConnectionAbort)
{
- ConnectFailedException ex(file, line);
- ex.error = static_cast<int>(error);
- throw ex;
+ throw ConnectFailedException(file, line, static_cast<int>(error));
}
else if(error == SocketErrorStatus::HostNotFound)
{
- DNSException ex(file, line);
- ex.error = static_cast<int>(error);
- throw ex;
+ throw DNSException(file, line, static_cast<int>(error), "");
}
else
{
- SocketException ex(file, line);
- ex.error = static_cast<int>(error);
- throw ex;
+ throw SocketException(file, line, static_cast<int>(error));
}
}
@@ -2896,30 +2804,22 @@ IceInternal::checkErrorCode(const char* file, int line, HRESULT herr)
{
if(herr == E_ACCESSDENIED)
{
- SocketException ex(file, line);
- ex.error = static_cast<int>(herr);
- throw ex;
+ throw SocketException(file, line, static_cast<int>(herr));
}
SocketErrorStatus error = SocketError::GetStatus(herr);
if(error == SocketErrorStatus::NetworkDroppedConnectionOnReset ||
error == SocketErrorStatus::SoftwareCausedConnectionAbort ||
error == SocketErrorStatus::ConnectionResetByPeer)
{
- ConnectionLostException ex(file, line);
- ex.error = static_cast<int>(error);
- throw ex;
+ throw ConnectionLostException(file, line, static_cast<int>(error));
}
else if(error == SocketErrorStatus::HostNotFound)
{
- DNSException ex(file, line);
- ex.error = static_cast<int>(error);
- throw ex;
+ throw DNSException(file, line, static_cast<int>(error), "");
}
else
{
- SocketException ex(file, line);
- ex.error = static_cast<int>(error);
- throw ex;
+ throw SocketException(file, line, static_cast<int>(error));
}
}
@@ -2989,9 +2889,7 @@ IceInternal::doConnectAsync(SOCKET fd, const Address& addr, const Address& sourc
if(::bind(fd, &bindAddr.sa, size) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
LPFN_CONNECTEX ConnectEx = ICE_NULLPTR; // a pointer to the 'ConnectEx()' function
@@ -3007,9 +2905,7 @@ IceInternal::doConnectAsync(SOCKET fd, const Address& addr, const Address& sourc
ICE_NULLPTR,
ICE_NULLPTR) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
if(!ConnectEx(fd, &addr.sa, size, 0, 0, 0, &info))
@@ -3018,21 +2914,15 @@ IceInternal::doConnectAsync(SOCKET fd, const Address& addr, const Address& sourc
{
if(connectionRefused())
{
- ConnectionRefusedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionRefusedException(__FILE__, __LINE__, getSocketErrno());
}
else if(connectFailed())
{
- ConnectFailedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectFailedException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
}
@@ -3051,29 +2941,21 @@ IceInternal::doFinishConnectAsync(SOCKET fd, AsyncInfo& info)
WSASetLastError(info.error);
if(connectionRefused())
{
- ConnectionRefusedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionRefusedException(__FILE__, __LINE__, getSocketErrno());
}
else if(connectFailed())
{
- ConnectFailedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectFailedException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
if(setsockopt(fd, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, ICE_NULLPTR, 0) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
#endif
diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp
index a24aa01b3f7..9fce2f852d5 100644
--- a/cpp/src/Ice/Object.cpp
+++ b/cpp/src/Ice/Object.cpp
@@ -334,14 +334,12 @@ Ice::Object::_iceCheckMode(OperationMode expected, OperationMode received)
}
else
{
- Ice::MarshalException ex(__FILE__, __LINE__);
std::ostringstream reason;
reason << "unexpected operation mode. expected = "
<< operationModeToString(expected)
<< " received = "
<< operationModeToString(received);
- ex.reason = reason.str();
- throw ex;
+ throw Ice::MarshalException(__FILE__, __LINE__, reason.str());
}
}
}
diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp
index b21fa4e9a15..0c3bf12a9a0 100644
--- a/cpp/src/Ice/ObjectAdapterI.cpp
+++ b/cpp/src/Ice/ObjectAdapterI.cpp
@@ -994,9 +994,7 @@ Ice::ObjectAdapterI::initialize(const RouterPrxPtr& router)
//
if(router == 0 && noProps)
{
- InitializationException ex(__FILE__, __LINE__);
- ex.reason = "object adapter `" + _name + "' requires configuration";
- throw ex;
+ throw InitializationException(__FILE__, __LINE__, "object adapter `" + _name + "' requires configuration");
}
const_cast<string&>(_id) = properties->getProperty(_name + ".AdapterId");
@@ -1013,9 +1011,8 @@ Ice::ObjectAdapterI::initialize(const RouterPrxPtr& router)
}
catch(const ProxyParseException&)
{
- InitializationException ex(__FILE__, __LINE__);
- ex.reason = "invalid proxy options `" + proxyOptions + "' for object adapter `" + _name + "'";
- throw ex;
+ throw InitializationException(__FILE__, __LINE__, "invalid proxy options `" + proxyOptions +
+ "' for object adapter `" + _name + "'");
}
const_cast<ACMConfig&>(_acm) =
@@ -1223,9 +1220,7 @@ Ice::ObjectAdapterI::checkForDeactivation() const
{
if(_state >= StateDeactivating)
{
- ObjectAdapterDeactivatedException ex(__FILE__, __LINE__);
- ex.name = getName();
- throw ex;
+ throw ObjectAdapterDeactivatedException(__FILE__, __LINE__, getName());
}
}
@@ -1397,10 +1392,7 @@ ObjectAdapterI::updateLocatorRegistry(const IceInternal::LocatorInfoPtr& locator
out << "the object adapter is not known to the locator registry";
}
- NotRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = "object adapter";
- ex.id = _id;
- throw ex;
+ throw NotRegisteredException(__FILE__, __LINE__, "object adapter", _id);
}
catch(const InvalidReplicaGroupIdException&)
{
@@ -1411,10 +1403,7 @@ ObjectAdapterI::updateLocatorRegistry(const IceInternal::LocatorInfoPtr& locator
out << "the replica group `" << _replicaGroupId << "' is not known to the locator registry";
}
- NotRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = "replica group";
- ex.id = _replicaGroupId;
- throw ex;
+ throw NotRegisteredException(__FILE__, __LINE__, "replica group", _replicaGroupId);
}
catch(const AdapterAlreadyActiveException&)
{
@@ -1425,9 +1414,7 @@ ObjectAdapterI::updateLocatorRegistry(const IceInternal::LocatorInfoPtr& locator
out << "the object adapter endpoints are already set";
}
- ObjectAdapterIdInUseException ex(__FILE__, __LINE__);
- ex.id = _id;
- throw ex;
+ throw ObjectAdapterIdInUseException(__FILE__, __LINE__, _id);
}
catch(const ObjectAdapterDeactivatedException&)
{
diff --git a/cpp/src/Ice/OpaqueEndpointI.cpp b/cpp/src/Ice/OpaqueEndpointI.cpp
index df53a9216cb..99f84a77a9f 100644
--- a/cpp/src/Ice/OpaqueEndpointI.cpp
+++ b/cpp/src/Ice/OpaqueEndpointI.cpp
@@ -35,15 +35,11 @@ IceInternal::OpaqueEndpointI::OpaqueEndpointI(vector<string>& args) :
if(_type < 0)
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no -t option in endpoint " + toString();
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no -t option in endpoint " + toString());
}
if(_rawBytes.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no -v option in endpoint " + toString();
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no -v option in endpoint " + toString());
}
}
@@ -342,29 +338,24 @@ IceInternal::OpaqueEndpointI::checkOption(const string& option, const string& ar
{
if(_type > -1)
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "multiple -t options in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "multiple -t options in endpoint " + endpoint);
}
if(argument.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -t option in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no argument provided for -t option in endpoint " +
+ endpoint);
}
istringstream p(argument);
Ice::Int t;
if(!(p >> t) || !p.eof())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid type value `" + argument + "' in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "invalid type value `" + argument + "' in endpoint " +
+ endpoint);
}
else if(t < 0 || t > 65535)
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "type value `" + argument + "' out of range in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "type value `" + argument + "' out of range in endpoint " +
+ endpoint);
}
_type = static_cast<Ice::Short>(t);
return true;
@@ -374,26 +365,20 @@ IceInternal::OpaqueEndpointI::checkOption(const string& option, const string& ar
{
if(!_rawBytes.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "multiple -v options in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "multiple -v options in endpoint " + endpoint);
}
if(argument.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -v option in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no argument provided for -v option in endpoint " + endpoint);
}
for(string::size_type i = 0; i < argument.size(); ++i)
{
if(!Base64::isBase64(argument[i]))
{
- EndpointParseException ex(__FILE__, __LINE__);
- ostringstream ostr;
- ostr << "invalid base64 character `" << argument[i] << "' (ordinal " << static_cast<int>(argument[i])
- << ") in endpoint " << endpoint;
- ex.str = ostr.str();
- throw ex;
+ ostringstream os;
+ os << "invalid base64 character `" << argument[i] << "' (ordinal " << static_cast<int>(argument[i])
+ << ") in endpoint " << endpoint;
+ throw EndpointParseException(__FILE__, __LINE__, os.str());
}
}
const_cast<vector<Byte>&>(_rawBytes) = Base64::decode(argument);
@@ -404,20 +389,18 @@ IceInternal::OpaqueEndpointI::checkOption(const string& option, const string& ar
{
if(argument.empty())
{
- Ice::EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -e option in endpoint " + endpoint;
- throw ex;
+ throw Ice::EndpointParseException(__FILE__, __LINE__, "no argument provided for -e option in endpoint " +
+ endpoint);
}
try
{
_rawEncoding = Ice::stringToEncodingVersion(argument);
}
- catch(const Ice::VersionParseException& e)
+ catch(const Ice::VersionParseException& ex)
{
- Ice::EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid encoding version `" + argument + "' in endpoint " + endpoint + ":\n" + e.str;
- throw ex;
+ throw Ice::EndpointParseException(__FILE__, __LINE__, "invalid encoding version `" + argument +
+ "' in endpoint " + endpoint + ":\n" + ex.str);
}
return true;
}
diff --git a/cpp/src/Ice/PluginManagerI.cpp b/cpp/src/Ice/PluginManagerI.cpp
index 1b43e00c1af..26aa11c95d8 100644
--- a/cpp/src/Ice/PluginManagerI.cpp
+++ b/cpp/src/Ice/PluginManagerI.cpp
@@ -73,9 +73,7 @@ Ice::PluginManagerI::initializePlugins()
{
if(_initialized)
{
- InitializationException ex(__FILE__, __LINE__);
- ex.reason = "plug-ins already initialized";
- throw ex;
+ throw InitializationException(__FILE__, __LINE__, "plug-ins already initialized");
}
//
@@ -161,10 +159,7 @@ Ice::PluginManagerI::getPlugin(const string& name)
return p;
}
- NotRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = _kindOfObject;
- ex.id = name;
- throw ex;
+ throw NotRegisteredException(__FILE__, __LINE__, _kindOfObject, name);
}
void
@@ -179,10 +174,7 @@ Ice::PluginManagerI::addPlugin(const string& name, const PluginPtr& plugin)
if(findPlugin(name))
{
- AlreadyRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = _kindOfObject;
- ex.id = name;
- throw ex;
+ throw AlreadyRegisteredException(__FILE__, __LINE__, _kindOfObject, name);
}
PluginInfo info;
@@ -311,9 +303,7 @@ Ice::PluginManagerI::loadPlugins(int& argc, const char* argv[])
if(findPlugin(name))
{
- PluginInitializationException ex(__FILE__, __LINE__);
- ex.reason = "plug-in `" + name + "' already loaded";
- throw ex;
+ throw PluginInitializationException(__FILE__, __LINE__, "plug-in `" + name + "' already loaded");
}
string property = prefix + name;
@@ -334,9 +324,7 @@ Ice::PluginManagerI::loadPlugins(int& argc, const char* argv[])
}
else
{
- PluginInitializationException ex(__FILE__, __LINE__);
- ex.reason = "plug-in `" + name + "' not defined";
- throw ex;
+ throw PluginInitializationException(__FILE__, __LINE__, "plug-in `" + name + "' not defined");
}
}
@@ -417,9 +405,8 @@ Ice::PluginManagerI::loadPlugin(const string& name, const string& pluginSpec, St
}
catch(const IceUtilInternal::BadOptException& ex)
{
- PluginInitializationException e(__FILE__, __LINE__);
- e.reason = "invalid arguments for plug-in `" + name + "':\n" + ex.reason;
- throw e;
+ throw PluginInitializationException(__FILE__, __LINE__, "invalid arguments for plug-in `" + name + "':\n" +
+ ex.reason);
}
assert(!args.empty());
@@ -468,16 +455,14 @@ Ice::PluginManagerI::loadPlugin(const string& name, const string& pluginSpec, St
DynamicLibrary::symbol_type sym = library->loadEntryPoint(entryPoint);
if(sym == 0)
{
- ostringstream out;
+ ostringstream os;
string msg = library->getErrorMessage();
- out << "unable to load entry point `" << entryPoint << "'";
+ os << "unable to load entry point `" << entryPoint << "'";
if(!msg.empty())
{
- out << ": " + msg;
+ os << ": " + msg;
}
- PluginInitializationException ex(__FILE__, __LINE__);
- ex.reason = out.str();
- throw ex;
+ throw PluginInitializationException(__FILE__, __LINE__, os.str());
}
#ifdef __IBMCPP__
@@ -495,11 +480,7 @@ Ice::PluginManagerI::loadPlugin(const string& name, const string& pluginSpec, St
PluginPtr plugin(factory(_communicator, name, args));
if(!plugin)
{
- PluginInitializationException e(__FILE__, __LINE__);
- ostringstream out;
- out << "failure in entry point `" << entryPoint << "'";
- e.reason = out.str();
- throw e;
+ throw PluginInitializationException(__FILE__, __LINE__, "failure in entry point `" + entryPoint + "'");
}
PluginInfo info;
diff --git a/cpp/src/Ice/PropertiesI.cpp b/cpp/src/Ice/PropertiesI.cpp
index 12b337f0987..5a65b119cc9 100644
--- a/cpp/src/Ice/PropertiesI.cpp
+++ b/cpp/src/Ice/PropertiesI.cpp
@@ -308,9 +308,8 @@ Ice::PropertiesI::load(const std::string& file)
LONG err;
if((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyName.c_str(), 0, KEY_QUERY_VALUE, &iceKey)) != ERROR_SUCCESS)
{
- InitializationException ex(__FILE__, __LINE__);
- ex.reason = "could not open Windows registry key `" + file + "':\n" + IceUtilInternal::errorToString(err);
- throw ex;
+ throw InitializationException(__FILE__, __LINE__, "could not open Windows registry key `" + file + "':\n" +
+ IceUtilInternal::errorToString(err));
}
DWORD maxNameSize; // Size in characters not including terminating null character.
@@ -322,10 +321,8 @@ Ice::PropertiesI::load(const std::string& file)
ICE_NULLPTR, ICE_NULLPTR);
if(err != ERROR_SUCCESS)
{
- InitializationException ex(__FILE__, __LINE__);
- ex.reason = "could not open Windows registry key `" + file + "':\n";
- ex.reason += IceUtilInternal::errorToString(err);
- throw ex;
+ throw InitializationException(__FILE__, __LINE__, "could not open Windows registry key `" + file + "':\n" +
+ IceUtilInternal::errorToString(err));
}
for(DWORD i = 0; i < numValues; ++i)
@@ -403,10 +400,7 @@ Ice::PropertiesI::load(const std::string& file)
ifstream in(IceUtilInternal::streamFilename(file).c_str());
if(!in)
{
- FileException ex(__FILE__, __LINE__);
- ex.path = file;
- ex.error = getSystemErrno();
- throw ex;
+ throw FileException(__FILE__, __LINE__, getSystemErrno(), file);
}
string line;
diff --git a/cpp/src/Ice/Protocol.cpp b/cpp/src/Ice/Protocol.cpp
index 808a7988158..3963f9ec8f4 100644
--- a/cpp/src/Ice/Protocol.cpp
+++ b/cpp/src/Ice/Protocol.cpp
@@ -68,34 +68,26 @@ stringToMajorMinor(const std::string& str, Ice::Byte& major, Ice::Byte& minor)
std::string::size_type pos = str.find_first_of(".");
if(pos == std::string::npos)
{
- Ice::VersionParseException ex(__FILE__, __LINE__);
- ex.str = "malformed version value `" + str + "'";
- throw ex;
+ throw Ice::VersionParseException(__FILE__, __LINE__, "malformed version value `" + str + "'");
}
std::istringstream majStr(str.substr(0, pos));
Ice::Int majVersion;
if(!(majStr >> majVersion) || !majStr.eof())
{
- Ice::VersionParseException ex(__FILE__, __LINE__);
- ex.str = "invalid major version value `" + str + "'";
- throw ex;
+ throw Ice::VersionParseException(__FILE__, __LINE__, "invalid major version value `" + str + "'");
}
std::istringstream minStr(str.substr(pos + 1, std::string::npos));
Ice::Int minVersion;
if(!(minStr >> minVersion) || !minStr.eof())
{
- Ice::VersionParseException ex(__FILE__, __LINE__);
- ex.str = "invalid minor version value `" + str + "'";
- throw ex;
+ throw Ice::VersionParseException(__FILE__, __LINE__, "invalid minor version value `" + str + "'");
}
if(majVersion < 1 || majVersion > 255 || minVersion < 0 || minVersion > 255)
{
- Ice::VersionParseException ex(__FILE__, __LINE__);
- ex.str = "range error in version `" + str + "'";
- throw ex;
+ throw Ice::VersionParseException(__FILE__, __LINE__, "range error in version `" + str + "'");
}
major = static_cast<Ice::Byte>(majVersion);
diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp
index 46a98263f62..3014387b52c 100644
--- a/cpp/src/Ice/ReferenceFactory.cpp
+++ b/cpp/src/Ice/ReferenceFactory.cpp
@@ -112,9 +112,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
beg = s.find_first_not_of(delim, end);
if(beg == string::npos)
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "no non-whitespace characters found in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "no non-whitespace characters found in `" + s + "'");
}
//
@@ -125,9 +123,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
end = IceUtilInternal::checkQuote(s, beg);
if(end == string::npos)
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "mismatched quotes around identity in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "mismatched quotes around identity in `" + s + "'");
}
else if(end == 0)
{
@@ -147,9 +143,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
if(beg == end)
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "no identity in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "no identity in `" + s + "'");
}
//
@@ -165,9 +159,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
//
if(!ident.category.empty())
{
- IllegalIdentityException e(__FILE__, __LINE__);
- e.id = ident;
- throw e;
+ throw IllegalIdentityException(__FILE__, __LINE__, ident);
}
//
// Treat a stringified proxy containing two double
@@ -177,9 +169,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
//
else if(s.find_first_not_of(delim, end) != string::npos)
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "invalid characters after identity in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "invalid characters after identity in `" + s + "'");
}
else
{
@@ -221,9 +211,8 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
string option = s.substr(beg, end - beg);
if(option.length() != 2 || option[0] != '-')
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "expected a proxy option but found `" + option + "' in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "expected a proxy option but found `" + option + "' in `" +
+ s + "'");
}
//
@@ -241,9 +230,8 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
end = IceUtilInternal::checkQuote(s, beg);
if(end == string::npos)
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "mismatched quotes around value for " + option + " option in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "mismatched quotes around value for " + option +
+ " option in `" + s + "'");
}
else if(end == 0)
{
@@ -273,20 +261,16 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
{
if(argument.empty())
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -f option in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "no argument provided for -f option in `" + s + "'");
}
try
{
facet = unescapeString(argument, 0, argument.size(), "");
}
- catch(const IceUtil::IllegalArgumentException& e)
+ catch(const IceUtil::IllegalArgumentException& ex)
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "invalid facet in `" + s + "': " + e.reason();
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "invalid facet in `" + s + "': " + ex.reason());
}
break;
@@ -296,9 +280,8 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
{
if(!argument.empty())
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "unexpected argument `" + argument + "' provided for -t option in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "unexpected argument `" + argument +
+ "' provided for -t option in `" + s + "'");
}
mode = Reference::ModeTwoway;
break;
@@ -308,9 +291,8 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
{
if(!argument.empty())
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "unexpected argument `" + argument + "' provided for -o option in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "unexpected argument `" + argument +
+ "' provided for -o option in `" + s + "'");
}
mode = Reference::ModeOneway;
break;
@@ -320,9 +302,8 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
{
if(!argument.empty())
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "unexpected argument `" + argument + "' provided for -O option in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "unexpected argument `" + argument +
+ "' provided for -O option in `" + s + "'");
}
mode = Reference::ModeBatchOneway;
break;
@@ -332,9 +313,8 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
{
if(!argument.empty())
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "unexpected argument `" + argument + "' provided for -d option in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "unexpected argument `" + argument +
+ "' provided for -d option in `" + s + "'");
}
mode = Reference::ModeDatagram;
break;
@@ -344,9 +324,8 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
{
if(!argument.empty())
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "unexpected argument `" + argument + "' provided for -D option in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "unexpected argument `" + argument +
+ "' provided for -D option in `" + s + "'");
}
mode = Reference::ModeBatchDatagram;
break;
@@ -356,9 +335,8 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
{
if(!argument.empty())
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "unexpected argument `" + argument + "' provided for -s option in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "unexpected argument `" + argument +
+ "' provided for -s option in `" + s + "'");
}
secure = true;
break;
@@ -368,20 +346,17 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
{
if(argument.empty())
{
- Ice::ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -e option in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "no argument provided for -e option in `" + s + "'");
}
try
{
encoding = Ice::stringToEncodingVersion(argument);
}
- catch(const Ice::VersionParseException& e)
+ catch(const Ice::VersionParseException& ex)
{
- Ice::ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "invalid encoding version `" + argument + "' in `" + s + "':\n" + e.str;
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "invalid encoding version `" + argument + "' in `" +
+ s + "':\n" + ex.str);
}
break;
}
@@ -390,29 +365,24 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
{
if(argument.empty())
{
- Ice::ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -p option in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "no argument provided for -p option in `" + s + "'");
}
try
{
protocol = Ice::stringToProtocolVersion(argument);
}
- catch(const Ice::VersionParseException& e)
+ catch(const Ice::VersionParseException& ex)
{
- Ice::ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "invalid protocol version `" + argument + "' in `" + s + "':\n" + e.str;
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "invalid protocol version `" + argument + "' in `" +
+ s + "':\n" + ex.str);
}
break;
}
default:
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "unknown option `" + option + "' in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "unknown option `" + option + "' in `" + s + "'");
}
}
}
@@ -491,9 +461,8 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
if(endpoints.size() == 0)
{
assert(!unknownEndpoints.empty());
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid endpoint `" + unknownEndpoints.front() + "' in `" + s + "'";
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "invalid endpoint `" + unknownEndpoints.front() +
+ "' in `" + s + "'");
}
else if(unknownEndpoints.size() != 0 &&
_instance->initializationData().properties->
@@ -515,18 +484,14 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
beg = s.find_first_not_of(delim, beg + 1);
if(beg == string::npos)
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "missing adapter id in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "missing adapter id in `" + s + "'");
}
string adapterstr;
end = IceUtilInternal::checkQuote(s, beg);
if(end == string::npos)
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "mismatched quotes around adapter id in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "mismatched quotes around adapter id in `" + s + "'");
}
else if(end == 0)
{
@@ -547,26 +512,21 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
// Check for trailing whitespace.
if(end != string::npos && s.find_first_not_of(delim, end) != string::npos)
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "invalid trailing characters after `" + s.substr(0, end + 1) + "' in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "invalid trailing characters after `" +
+ s.substr(0, end + 1) + "' in `" + s + "'");
}
try
{
adapter = unescapeString(adapterstr, 0, adapterstr.size(), "");
}
- catch(const IceUtil::IllegalArgumentException& e)
+ catch(const IceUtil::IllegalArgumentException& ex)
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "invalid adapter id in `" + s + "': " + e.reason();
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "invalid adapter id in `" + s + "': " + ex.reason());
}
if(adapter.size() == 0)
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "empty adapter id in `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "empty adapter id in `" + s + "'");
}
return create(ident, facet, mode, secure, protocol, encoding, endpoints, adapter, propertyPrefix);
@@ -574,9 +534,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
}
default:
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = "malformed proxy `" + s + "'";
- throw ex;
+ throw ProxyParseException(__FILE__, __LINE__, "malformed proxy `" + s + "'");
}
}
@@ -865,9 +823,8 @@ IceInternal::ReferenceFactory::create(const Identity& ident,
}
else
{
- EndpointSelectionTypeParseException ex(__FILE__, __LINE__);
- ex.str = "illegal value `" + type + "'; expected `Random' or `Ordered'";
- throw ex;
+ throw EndpointSelectionTypeParseException(__FILE__, __LINE__, "illegal value `" + type +
+ "'; expected `Random' or `Ordered'");
}
}
diff --git a/cpp/src/Ice/Selector.cpp b/cpp/src/Ice/Selector.cpp
index 8e5dcb901e6..61fd47a4f2c 100644
--- a/cpp/src/Ice/Selector.cpp
+++ b/cpp/src/Ice/Selector.cpp
@@ -52,9 +52,7 @@ Selector::setup(int sizeIO)
_handle = CreateIoCompletionPort(INVALID_HANDLE_VALUE, ICE_NULLPTR, 0, sizeIO);
if(_handle == ICE_NULLPTR)
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = GetLastError();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, GetLastError());
}
}
#endif
@@ -78,9 +76,7 @@ Selector::initialize(EventHandler* handler)
HANDLE socket = reinterpret_cast<HANDLE>(handler->getNativeInfo()->fd());
if(CreateIoCompletionPort(socket, _handle, reinterpret_cast<ULONG_PTR>(handler), 0) == ICE_NULLPTR)
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = GetLastError();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, GetLastError());
}
handler->getNativeInfo()->initialize(_handle, reinterpret_cast<ULONG_PTR>(handler));
#else
@@ -227,9 +223,7 @@ Selector::completed(EventHandler* handler, SocketOperation op)
}
if(!PostQueuedCompletionStatus(_handle, 0, reinterpret_cast<ULONG_PTR>(handler), info))
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = GetLastError();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, GetLastError());
}
#else
IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor);
@@ -253,9 +247,7 @@ Selector::Selector(const InstancePtr& instance) : _instance(instance), _interrup
_queueFd = epoll_create(1);
if(_queueFd < 0)
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
epoll_event event;
@@ -272,9 +264,7 @@ Selector::Selector(const InstancePtr& instance) : _instance(instance), _interrup
_queueFd = kqueue();
if(_queueFd < 0)
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, getSocketErrno());
}
struct kevent ev;
@@ -527,9 +517,7 @@ Selector::wakeup()
continue;
}
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
break;
}
@@ -552,9 +540,7 @@ Selector::startSelect()
{
continue;
}
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
break;
}
diff --git a/cpp/src/Ice/ServantManager.cpp b/cpp/src/Ice/ServantManager.cpp
index ba32e2c9fba..9b4965e8186 100644
--- a/cpp/src/Ice/ServantManager.cpp
+++ b/cpp/src/Ice/ServantManager.cpp
@@ -42,15 +42,14 @@ IceInternal::ServantManager::addServant(const ObjectPtr& object, const Identity&
{
if(p->second.find(facet) != p->second.end())
{
- AlreadyRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = "servant";
ToStringMode toStringMode = _instance->toStringMode();
- ex.id = Ice::identityToString(ident, toStringMode);
+ ostringstream os;
+ os << Ice::identityToString(ident, toStringMode);
if(!facet.empty())
{
- ex.id += " -f " + escapeString(facet, "", toStringMode);
+ os << " -f " << escapeString(facet, "", toStringMode);
}
- throw ex;
+ throw AlreadyRegisteredException(__FILE__, __LINE__, "servant", os.str());
}
}
@@ -69,10 +68,7 @@ IceInternal::ServantManager::addDefaultServant(const ObjectPtr& object, const st
DefaultServantMap::iterator p = _defaultServantMap.find(category);
if(p != _defaultServantMap.end())
{
- AlreadyRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = "default servant";
- ex.id = category;
- throw ex;
+ throw AlreadyRegisteredException(__FILE__, __LINE__, "default servant", category);
}
_defaultServantMap.insert(pair<const string, ObjectPtr>(category, object));
@@ -102,15 +98,14 @@ IceInternal::ServantManager::removeServant(const Identity& ident, const string&
if(p == _servantMapMap.end() || (q = p->second.find(facet)) == p->second.end())
{
- NotRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = "servant";
ToStringMode toStringMode = _instance->toStringMode();
- ex.id = Ice::identityToString(ident, toStringMode);
+ ostringstream os;
+ os << Ice::identityToString(ident, toStringMode);
if(!facet.empty())
{
- ex.id += " -f " + escapeString(facet, "", toStringMode);
+ os << " -f " + escapeString(facet, "", toStringMode);
}
- throw ex;
+ throw NotRegisteredException(__FILE__, __LINE__, "servant", os.str());
}
servant = q->second;
@@ -148,10 +143,7 @@ IceInternal::ServantManager::removeDefaultServant(const string& category)
DefaultServantMap::iterator p = _defaultServantMap.find(category);
if(p == _defaultServantMap.end())
{
- NotRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = "default servant";
- ex.id = category;
- throw ex;
+ throw NotRegisteredException(__FILE__, __LINE__, "default servant", category);
}
servant = p->second;
@@ -176,10 +168,8 @@ IceInternal::ServantManager::removeAllFacets(const Identity& ident)
if(p == _servantMapMap.end())
{
- NotRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = "servant";
- ex.id = Ice::identityToString(ident, _instance->toStringMode());
- throw ex;
+ throw NotRegisteredException(__FILE__, __LINE__, "servant",
+ Ice::identityToString(ident, _instance->toStringMode()));
}
FacetMap result = p->second;
@@ -333,10 +323,7 @@ IceInternal::ServantManager::addServantLocator(const ServantLocatorPtr& locator,
if((_locatorMapHint != _locatorMap.end() && _locatorMapHint->first == category)
|| _locatorMap.find(category) != _locatorMap.end())
{
- AlreadyRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = "servant locator";
- ex.id = category;
- throw ex;
+ throw AlreadyRegisteredException(__FILE__, __LINE__, "servant locator", category);
}
_locatorMapHint = _locatorMap.insert(_locatorMapHint, pair<const string, ServantLocatorPtr>(category, locator));
@@ -365,10 +352,7 @@ IceInternal::ServantManager::removeServantLocator(const string& category)
if(p == _locatorMap.end())
{
- NotRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = "servant locator";
- ex.id = category;
- throw ex;
+ throw NotRegisteredException(__FILE__, __LINE__, "servant locator", category);
}
ServantLocatorPtr locator = p->second;
diff --git a/cpp/src/Ice/Service.cpp b/cpp/src/Ice/Service.cpp
index 260ce660ed5..324abfc1115 100644
--- a/cpp/src/Ice/Service.cpp
+++ b/cpp/src/Ice/Service.cpp
@@ -221,9 +221,7 @@ public:
_source = RegisterEventSourceW(0, stringToWstring(mangleSource(source), _stringConverter).c_str());
if(_source == 0)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = GetLastError();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, GetLastError());
}
}
@@ -248,9 +246,7 @@ public:
if(err != ERROR_SUCCESS)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = err;
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, err);
}
//
@@ -261,9 +257,7 @@ public:
if(!GetModuleFileNameW(_module, path, _MAX_PATH))
{
RegCloseKey(hKey);
- SyscallException ex(__FILE__, __LINE__);
- ex.error = GetLastError();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, GetLastError());
}
//
@@ -287,9 +281,7 @@ public:
if(err != ERROR_SUCCESS)
{
RegCloseKey(hKey);
- SyscallException ex(__FILE__, __LINE__);
- ex.error = err;
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, err);
}
RegCloseKey(hKey);
@@ -306,9 +298,7 @@ public:
stringToWstring(createKey(source), stringConverter).c_str());
if(err != ERROR_SUCCESS)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = err;
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, err);
}
}
@@ -1620,9 +1610,7 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa
//
if(setsid() == -1)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno());
}
//
@@ -1637,9 +1625,7 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa
pid = fork();
if(pid < 0)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno());
}
if(pid != 0)
{
@@ -1653,9 +1639,7 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa
//
if(chdir("/") != 0)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno());
}
}
@@ -1671,9 +1655,7 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa
int fdMax = static_cast<int>(sysconf(_SC_OPEN_MAX));
if(fdMax <= 0)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno());
}
for(int i = 0; i < fdMax; ++i)
@@ -1733,9 +1715,7 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa
assert(fd == 0);
if(fd != 0)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno());
}
if(stdOut.empty())
{
@@ -1743,9 +1723,7 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa
assert(fd == 1);
if(fd != 1)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno());
}
}
if(stdErr.empty())
@@ -1754,9 +1732,7 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa
assert(fd == 2);
if(fd != 2)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno());
}
}
}
diff --git a/cpp/src/Ice/StreamSocket.cpp b/cpp/src/Ice/StreamSocket.cpp
index 912916e5ed3..80a45355bb0 100755
--- a/cpp/src/Ice/StreamSocket.cpp
+++ b/cpp/src/Ice/StreamSocket.cpp
@@ -246,9 +246,7 @@ StreamSocket::read(char* buf, size_t length)
#endif
if(ret == 0)
{
- Ice::ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, 0);
}
else if(ret == SOCKET_ERROR)
{
@@ -270,15 +268,11 @@ StreamSocket::read(char* buf, size_t length)
if(connectionLost())
{
- Ice::ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
@@ -319,9 +313,7 @@ StreamSocket::write(const char* buf, size_t length)
#endif
if(ret == 0)
{
- Ice::ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, 0);
}
else if(ret == SOCKET_ERROR)
{
@@ -343,15 +335,11 @@ StreamSocket::write(const char* buf, size_t length)
if(connectionLost())
{
- Ice::ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
@@ -409,15 +397,11 @@ StreamSocket::startWrite(Buffer& buf)
{
if(connectionLost())
{
- Ice::ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
}
@@ -437,15 +421,11 @@ StreamSocket::finishWrite(Buffer& buf)
WSASetLastError(_write.error);
if(connectionLost())
{
- Ice::ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
@@ -472,15 +452,11 @@ StreamSocket::startRead(Buffer& buf)
{
if(connectionLost())
{
- Ice::ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
}
@@ -499,22 +475,16 @@ StreamSocket::finishRead(Buffer& buf)
WSASetLastError(_read.error);
if(connectionLost())
{
- Ice::ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
else if(_read.count == 0)
{
- Ice::ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, 0);
}
buf.i += _read.count;
@@ -620,9 +590,7 @@ StreamSocket::finishRead(Buffer& buf)
}
else if(_read.count == 0)
{
- Ice::ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, 0);
}
try
diff --git a/cpp/src/Ice/TcpAcceptor.cpp b/cpp/src/Ice/TcpAcceptor.cpp
index 643acf96eab..c486707cd14 100755
--- a/cpp/src/Ice/TcpAcceptor.cpp
+++ b/cpp/src/Ice/TcpAcceptor.cpp
@@ -125,9 +125,7 @@ IceInternal::TcpAcceptor::startAccept()
ICE_NULLPTR,
ICE_NULLPTR) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
assert(_acceptFd == INVALID_SOCKET);
@@ -137,9 +135,7 @@ IceInternal::TcpAcceptor::startAccept()
{
if(!wouldBlock())
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
}
@@ -160,18 +156,14 @@ IceInternal::TcpAcceptor::accept()
{
if(_acceptFd == INVALID_SOCKET)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = _acceptError;
- throw ex;
+ throw SocketException(__FILE__, __LINE__, _acceptError);
}
if(setsockopt(_acceptFd, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, (char*)&_acceptFd, sizeof(_acceptFd)) ==
SOCKET_ERROR)
{
closeSocketNoThrow(_acceptFd);
_acceptFd = INVALID_SOCKET;
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
SOCKET fd = _acceptFd;
diff --git a/cpp/src/Ice/TcpEndpointI.cpp b/cpp/src/Ice/TcpEndpointI.cpp
index 57a44ac4b20..36b8fda3ed1 100644
--- a/cpp/src/Ice/TcpEndpointI.cpp
+++ b/cpp/src/Ice/TcpEndpointI.cpp
@@ -288,9 +288,8 @@ IceInternal::TcpEndpointI::checkOption(const string& option, const string& argum
{
if(argument.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -t option in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no argument provided for -t option in endpoint " +
+ endpoint);
}
if(argument == "infinite")
@@ -302,9 +301,8 @@ IceInternal::TcpEndpointI::checkOption(const string& option, const string& argum
istringstream t(argument);
if(!(t >> const_cast<Int&>(_timeout)) || !t.eof() || _timeout < 1)
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid timeout value `" + argument + "' in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "invalid timeout value `" + argument +
+ "' in endpoint " + endpoint);
}
}
return true;
@@ -314,9 +312,8 @@ IceInternal::TcpEndpointI::checkOption(const string& option, const string& argum
{
if(!argument.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "unexpected argument `" + argument + "' provided for -z option in " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "unexpected argument `" + argument +
+ "' provided for -z option in " + endpoint);
}
const_cast<bool&>(_compress) = true;
return true;
diff --git a/cpp/src/Ice/UdpEndpointI.cpp b/cpp/src/Ice/UdpEndpointI.cpp
index 11f7d565008..7574935e75d 100644
--- a/cpp/src/Ice/UdpEndpointI.cpp
+++ b/cpp/src/Ice/UdpEndpointI.cpp
@@ -198,9 +198,8 @@ IceInternal::UdpEndpointI::initWithOptions(vector<string>& args, bool oaEndpoint
}
else
{
- Ice::EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "`--interface *' not valid for proxy endpoint `" + toString() + "'";
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "`--interface *' not valid for proxy endpoint `" +
+ toString() + "'");
}
}
}
@@ -385,9 +384,8 @@ IceInternal::UdpEndpointI::checkOption(const string& option, const string& argum
{
if(!argument.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "unexpected argument `" + argument + "' provided for -c option in " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "unexpected argument `" + argument +
+ "' provided for -c option in " + endpoint);
}
const_cast<bool&>(_connect) = true;
}
@@ -395,9 +393,8 @@ IceInternal::UdpEndpointI::checkOption(const string& option, const string& argum
{
if(!argument.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "unexpected argument `" + argument + "' provided for -z option in " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "unexpected argument `" + argument +
+ "' provided for -z option in " + endpoint);
}
const_cast<bool&>(_compress) = true;
}
@@ -405,9 +402,8 @@ IceInternal::UdpEndpointI::checkOption(const string& option, const string& argum
{
if(argument.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for " + option + " option in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no argument provided for " + option +
+ " option in endpoint " + endpoint);
}
try
{
@@ -418,20 +414,18 @@ IceInternal::UdpEndpointI::checkOption(const string& option, const string& argum
_instance->logger()->warning("deprecated udp endpoint option: " + option);
}
}
- catch(const VersionParseException& e)
+ catch(const VersionParseException& ex)
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid version `" + argument + "' in endpoint " + endpoint + ":\n" + e.str;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "invalid version `" + argument + "' in endpoint " +
+ endpoint + ":\n" + ex.str);
}
}
else if(option == "--interface")
{
if(argument.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for --interface option in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no argument provided for --interface option in endpoint "
+ + endpoint);
}
const_cast<string&>(_mcastInterface) = argument;
}
@@ -439,16 +433,14 @@ IceInternal::UdpEndpointI::checkOption(const string& option, const string& argum
{
if(argument.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for --ttl option in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no argument provided for --ttl option in endpoint " +
+ endpoint);
}
istringstream p(argument);
if(!(p >> const_cast<Int&>(_mcastTtl)) || !p.eof())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid TTL value `" + argument + "' in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "invalid TTL value `" + argument + "' in endpoint " +
+ endpoint);
}
}
else
diff --git a/cpp/src/Ice/UdpTransceiver.cpp b/cpp/src/Ice/UdpTransceiver.cpp
index 32a3f67b5b9..87b2790f60e 100755
--- a/cpp/src/Ice/UdpTransceiver.cpp
+++ b/cpp/src/Ice/UdpTransceiver.cpp
@@ -216,9 +216,7 @@ repeat:
else
{
// No peer has sent a datagram yet.
- SocketException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
+ throw SocketException(__FILE__, __LINE__, 0);
}
# ifdef _WIN32
@@ -242,9 +240,7 @@ repeat:
return SocketOperationWrite;
}
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
assert(ret == static_cast<ssize_t>(buf.b.size()));
@@ -318,15 +314,11 @@ repeat:
if(connectionLost())
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
}
@@ -487,9 +479,7 @@ IceInternal::UdpTransceiver::startWrite(Buffer& buf)
else
{
// No peer has sent a datagram yet.
- SocketException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
+ throw SocketException(__FILE__, __LINE__, 0);
}
err = WSASendTo(_fd, &_write.buf, 1, &_write.count, 0, &_peerAddr.sa,
len, &_write, ICE_NULLPTR);
@@ -501,15 +491,11 @@ IceInternal::UdpTransceiver::startWrite(Buffer& buf)
{
if(connectionLost())
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
}
@@ -601,15 +587,11 @@ IceInternal::UdpTransceiver::finishWrite(Buffer& buf)
WSASetLastError(_write.error);
if(connectionLost())
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__ ,getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
#else
checkErrorCode(__FILE__, __LINE__, _write.error);
@@ -654,15 +636,11 @@ IceInternal::UdpTransceiver::startRead(Buffer& buf)
{
if(connectionLost())
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
}
@@ -730,15 +708,11 @@ IceInternal::UdpTransceiver::finishRead(Buffer& buf)
{
if(connectionLost())
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
}
diff --git a/cpp/src/Ice/ValueFactoryManagerI.cpp b/cpp/src/Ice/ValueFactoryManagerI.cpp
index cded3c2b045..bcca00dfe5d 100644
--- a/cpp/src/Ice/ValueFactoryManagerI.cpp
+++ b/cpp/src/Ice/ValueFactoryManagerI.cpp
@@ -23,10 +23,7 @@ IceInternal::ValueFactoryManagerI::add(ICE_IN(ICE_DELEGATE(ValueFactory)) factor
if((_factoryMapHint != _factoryMap.end() && _factoryMapHint->first == id)
|| _factoryMap.find(id) != _factoryMap.end())
{
- AlreadyRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = "value factory";
- ex.id = id;
- throw ex;
+ throw AlreadyRegisteredException(__FILE__, __LINE__, "value factory", id);
}
_factoryMapHint = _factoryMap.insert(_factoryMapHint, pair<const string, ICE_DELEGATE(ValueFactory)>(id, factory));
diff --git a/cpp/src/Ice/WSEndpoint.cpp b/cpp/src/Ice/WSEndpoint.cpp
index 386125545d4..2ef8faa0175 100644
--- a/cpp/src/Ice/WSEndpoint.cpp
+++ b/cpp/src/Ice/WSEndpoint.cpp
@@ -475,9 +475,8 @@ IceInternal::WSEndpoint::checkOption(const string& option, const string& argumen
{
if(argument.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -r option in endpoint " + endpoint + _delegate->options();
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no argument provided for -r option in endpoint " +
+ endpoint + _delegate->options());
}
const_cast<string&>(_resource) = argument;
return true;
diff --git a/cpp/src/Ice/WSTransceiver.cpp b/cpp/src/Ice/WSTransceiver.cpp
index f8254a2e606..8d652aa0972 100644
--- a/cpp/src/Ice/WSTransceiver.cpp
+++ b/cpp/src/Ice/WSTransceiver.cpp
@@ -1315,9 +1315,7 @@ IceInternal::WSTransceiver::preRead(Buffer& buf)
}
else
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, 0);
}
}
case OP_PING:
@@ -1620,9 +1618,7 @@ IceInternal::WSTransceiver::postWrite(Buffer& buf)
}
else
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, 0);
}
}
else if(_state == StateClosed)
diff --git a/cpp/src/Ice/ios/StreamEndpointI.cpp b/cpp/src/Ice/ios/StreamEndpointI.cpp
index 7c2ad1a4738..45b4b5cdf7b 100644
--- a/cpp/src/Ice/ios/StreamEndpointI.cpp
+++ b/cpp/src/Ice/ios/StreamEndpointI.cpp
@@ -385,9 +385,8 @@ IceObjC::StreamEndpointI::checkOption(const string& option, const string& argume
{
if(argument.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -t option in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no argument provided for -t option in endpoint " +
+ endpoint);
}
if(argument == "infinite")
@@ -399,9 +398,8 @@ IceObjC::StreamEndpointI::checkOption(const string& option, const string& argume
istringstream t(argument);
if(!(t >> const_cast<Int&>(_timeout)) || !t.eof() || _timeout < 1)
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid timeout value `" + argument + "' in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "invalid timeout value `" + argument +
+ "' in endpoint " + endpoint);
}
}
return true;
@@ -411,9 +409,8 @@ IceObjC::StreamEndpointI::checkOption(const string& option, const string& argume
{
if(!argument.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "unexpected argument `" + argument + "' provided for -z option in " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "unexpected argument `" + argument +
+ "' provided for -z option in " + endpoint);
}
const_cast<bool&>(_compress) = true;
return true;
diff --git a/cpp/src/Ice/ios/StreamTransceiver.cpp b/cpp/src/Ice/ios/StreamTransceiver.cpp
index cc0624fee78..7eba9c5f83a 100644
--- a/cpp/src/Ice/ios/StreamTransceiver.cpp
+++ b/cpp/src/Ice/ios/StreamTransceiver.cpp
@@ -374,9 +374,7 @@ IceObjC::StreamTransceiver::read(Buffer& buf)
if(ret == 0)
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, 0);
}
if(ret == SOCKET_ERROR)
@@ -521,27 +519,19 @@ IceObjC::StreamTransceiver::checkErrorStatus(CFWriteStreamRef writeStream, CFRea
}
else if(connectionLost())
{
- ConnectionLostException ex(file, line);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionLostException(file, line, getSocketErrno());
}
else if(connectionRefused())
{
- ConnectionRefusedException ex(file, line);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionRefusedException(file, line, getSocketErrno());
}
else if(connectFailed())
{
- ConnectFailedException ex(file, line);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectFailedException(file, line, getSocketErrno());
}
else
{
- SocketException ex(file, line);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(file, line, getSocketErrno());
}
}
@@ -558,14 +548,7 @@ IceObjC::StreamTransceiver::checkErrorStatus(CFWriteStreamRef writeStream, CFRea
CFNumberGetValue(d, kCFNumberSInt32Type, &rs);
}
}
- DNSException ex(file, line);
- ex.error = rs;
- ex.host = _host;
- throw ex;
+ throw DNSException(file, line, rs, _host);
}
-
- CFNetworkException ex(file, line);
- ex.domain = fromCFString(domain);
- ex.error = CFErrorGetCode(err.get());
- throw ex;
+ throw CFNetworkException(file, line, CFErrorGetCode(err.get()), domain);
}
diff --git a/cpp/src/IceBT/AcceptorI.cpp b/cpp/src/IceBT/AcceptorI.cpp
index 56e15ceb454..1efa538b012 100644
--- a/cpp/src/IceBT/AcceptorI.cpp
+++ b/cpp/src/IceBT/AcceptorI.cpp
@@ -89,13 +89,13 @@ IceBT::AcceptorI::listen()
}
catch(const BluetoothException& ex)
{
- InitializationException e(__FILE__, __LINE__);
- e.reason = "unable to register Bluetooth profile";
+ ostringstream os;
+ os << "unable to register Bluetooth profile";
if(!ex.reason.empty())
{
- e.reason += "\n" + ex.reason;
+ os << "\n" << ex.reason;
}
- throw e;
+ throw InitializationException(__FILE__, __LINE__, os.str());
}
_endpoint = _endpoint->endpoint(this);
@@ -110,9 +110,7 @@ IceBT::AcceptorI::accept()
//
if(!_instance->initialized())
{
- PluginInitializationException ex(__FILE__, __LINE__);
- ex.reason = "IceBT: plug-in is not initialized";
- throw ex;
+ throw PluginInitializationException(__FILE__, __LINE__, "IceBT: plug-in is not initialized");
}
IceInternal::TransceiverPtr t;
@@ -215,15 +213,13 @@ IceBT::AcceptorI::AcceptorI(const EndpointIPtr& endpoint, const InstancePtr& ins
DeviceAddress da;
if(!parseDeviceAddress(s, da))
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid address value `" + s + "' in endpoint " + endpoint->toString();
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "invalid address value `" + s + "' in endpoint " +
+ endpoint->toString());
}
if(!_instance->engine()->adapterExists(s))
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no device found for `" + s + "' in endpoint " + endpoint->toString();
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no device found for `" + s + "' in endpoint " +
+ endpoint->toString());
}
const_cast<string&>(_addr) = s;
diff --git a/cpp/src/IceBT/ConnectorI.cpp b/cpp/src/IceBT/ConnectorI.cpp
index 61894d2242b..946b01f23e0 100644
--- a/cpp/src/IceBT/ConnectorI.cpp
+++ b/cpp/src/IceBT/ConnectorI.cpp
@@ -25,9 +25,7 @@ IceBT::ConnectorI::connect()
//
if(!_instance->initialized())
{
- PluginInitializationException ex(__FILE__, __LINE__);
- ex.reason = "IceBT: plug-in is not initialized";
- throw ex;
+ throw PluginInitializationException(__FILE__, __LINE__, "IceBT: plug-in is not initialized");
}
//
diff --git a/cpp/src/IceBT/EndpointI.cpp b/cpp/src/IceBT/EndpointI.cpp
index 40726c63b82..f309352b96e 100644
--- a/cpp/src/IceBT/EndpointI.cpp
+++ b/cpp/src/IceBT/EndpointI.cpp
@@ -457,9 +457,8 @@ IceBT::EndpointI::initWithOptions(vector<string>& args, bool oaEndpoint)
}
else
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "a device address must be specified using the -a option or Ice.Default.Host";
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__,
+ "a device address must be specified using the -a option or Ice.Default.Host");
}
}
@@ -479,9 +478,7 @@ IceBT::EndpointI::initWithOptions(vector<string>& args, bool oaEndpoint)
}
else
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "a UUID must be specified using the -u option";
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "a UUID must be specified using the -u option");
}
}
@@ -492,9 +489,7 @@ IceBT::EndpointI::initWithOptions(vector<string>& args, bool oaEndpoint)
if(!oaEndpoint && _channel != 0)
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "the -c option can only be used for object adapter endpoints";
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "the -c option can only be used for object adapter endpoints");
}
hashInit();
@@ -527,15 +522,13 @@ IceBT::EndpointI::checkOption(const string& option, const string& argument, cons
{
if(arg.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -a option in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no argument provided for -a option in endpoint " +
+ endpoint);
}
if(arg != "*" && !isValidDeviceAddress(arg))
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid argument provided for -a option in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "invalid argument provided for -a option in endpoint " +
+ endpoint);
}
const_cast<string&>(_addr) = arg;
}
@@ -543,9 +536,8 @@ IceBT::EndpointI::checkOption(const string& option, const string& argument, cons
{
if(arg.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -u option in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no argument provided for -u option in endpoint " +
+ endpoint);
}
const_cast<string&>(_uuid) = arg;
}
@@ -553,26 +545,23 @@ IceBT::EndpointI::checkOption(const string& option, const string& argument, cons
{
if(arg.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -c option in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no argument provided for -c option in endpoint " +
+ endpoint);
}
istringstream t(argument);
if(!(t >> const_cast<Int&>(_channel)) || !t.eof() || _channel < 0 || _channel > 30)
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid channel value `" + arg + "' in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "invalid channel value `" + arg + "' in endpoint " +
+ endpoint);
}
}
else if(option == "-t")
{
if(arg.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -t option in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no argument provided for -t option in endpoint " +
+ endpoint);
}
if(arg == "infinite")
@@ -584,9 +573,8 @@ IceBT::EndpointI::checkOption(const string& option, const string& argument, cons
istringstream t(argument);
if(!(t >> const_cast<Int&>(_timeout)) || !t.eof() || _timeout < 1)
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid timeout value `" + arg + "' in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "invalid timeout value `" + arg + "' in endpoint " +
+ endpoint);
}
}
}
@@ -594,9 +582,8 @@ IceBT::EndpointI::checkOption(const string& option, const string& argument, cons
{
if(!arg.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "unexpected argument `" + arg + "' provided for -z option in " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "unexpected argument `" + arg +
+ "' provided for -z option in " + endpoint);
}
const_cast<bool&>(_compress) = true;
}
@@ -604,9 +591,8 @@ IceBT::EndpointI::checkOption(const string& option, const string& argument, cons
{
if(arg.empty())
{
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for --name option in endpoint " + endpoint;
- throw ex;
+ throw EndpointParseException(__FILE__, __LINE__, "no argument provided for --name option in endpoint " +
+ endpoint);
}
const_cast<string&>(_name) = arg;
}
diff --git a/cpp/src/IceBT/StreamSocket.cpp b/cpp/src/IceBT/StreamSocket.cpp
index 6cc5c67c741..15a5d7eaf54 100644
--- a/cpp/src/IceBT/StreamSocket.cpp
+++ b/cpp/src/IceBT/StreamSocket.cpp
@@ -128,9 +128,7 @@ IceBT::StreamSocket::read(char* buf, size_t length)
ssize_t ret = ::recv(_fd, buf, packetSize, 0);
if(ret == 0)
{
- Ice::ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, 0);
}
else if(ret == SOCKET_ERROR)
{
@@ -152,15 +150,11 @@ IceBT::StreamSocket::read(char* buf, size_t length)
if(IceInternal::connectionLost())
{
- Ice::ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
else
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
}
@@ -189,9 +183,7 @@ IceBT::StreamSocket::write(const char* buf, size_t length)
ssize_t ret = ::send(_fd, buf, packetSize, 0);
if(ret == 0)
{
- Ice::ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, 0);
}
else if(ret == SOCKET_ERROR)
{
@@ -213,15 +205,11 @@ IceBT::StreamSocket::write(const char* buf, size_t length)
if(IceInternal::connectionLost())
{
- Ice::ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw Ice::ConnectionLostException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
else
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
}
diff --git a/cpp/src/IceBT/Util.cpp b/cpp/src/IceBT/Util.cpp
index 0ac06c45500..3a6586203e2 100644
--- a/cpp/src/IceBT/Util.cpp
+++ b/cpp/src/IceBT/Util.cpp
@@ -104,9 +104,7 @@ fdToLocalAddress(SOCKET fd, SocketAddress& addr)
if(::getsockname(fd, reinterpret_cast<struct sockaddr*>(&addr), &len) == SOCKET_ERROR)
{
IceInternal::closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
}
@@ -123,9 +121,7 @@ fdToRemoteAddress(SOCKET fd, SocketAddress& addr)
else
{
IceInternal::closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
}
diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp
index 2f027994814..0f26b5a6c30 100644
--- a/cpp/src/IceBox/ServiceManagerI.cpp
+++ b/cpp/src/IceBox/ServiceManagerI.cpp
@@ -50,9 +50,8 @@ struct StartServiceInfo
}
catch(const IceUtilInternal::BadOptException& ex)
{
- FailureException e(__FILE__, __LINE__);
- e.reason = "ServiceManager: invalid arguments for service `" + name + "':\n" + ex.reason;
- throw e;
+ throw FailureException(__FILE__, __LINE__, "ServiceManager: invalid arguments for service `" + name +
+ "':\n" + ex.reason);
}
assert(!args.empty());
@@ -365,9 +364,8 @@ IceBox::ServiceManagerI::start()
p = services.find(prefix + *q);
if(p == services.end())
{
- FailureException ex(__FILE__, __LINE__);
- ex.reason = "ServiceManager: no service definition for `" + *q + "'";
- throw ex;
+ throw FailureException(__FILE__, __LINE__, "ServiceManager: no service definition for `" +
+ *q + "'");
}
servicesInfo.push_back(StartServiceInfo(*q, p->second, _argv));
services.erase(p);
@@ -558,14 +556,14 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint,
IceInternal::DynamicLibrary::symbol_type sym = library->loadEntryPoint(entryPoint, false);
if(sym == 0)
{
- string msg = library->getErrorMessage();
- FailureException ex(__FILE__, __LINE__);
- ex.reason = "ServiceManager: unable to load entry point `" + entryPoint + "'";
+ ostringstream os;
+ os << "ServiceManager: unable to load entry point `" << entryPoint << "'";
+ const string msg = library->getErrorMessage();
if(!msg.empty())
{
- ex.reason += ": " + msg;
+ os << ": " + msg;
}
- throw ex;
+ throw FailureException(__FILE__, __LINE__, os.str());
}
ServiceInfo info;
@@ -667,9 +665,7 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint,
s << "ServiceManager: exception while starting service " << service << ":\n";
s << ex;
- FailureException e(__FILE__, __LINE__);
- e.reason = s.str();
- throw e;
+ throw FailureException(__FILE__, __LINE__, s.str());
}
}
@@ -698,18 +694,14 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint,
s << "ServiceManager: exception in entry point `" + entryPoint + "' for service " << info.name << ":\n";
s << ex;
- FailureException e(__FILE__, __LINE__);
- e.reason = s.str();
- throw e;
+ throw FailureException(__FILE__, __LINE__, s.str());
}
catch(...)
{
ostringstream s;
s << "ServiceManager: unknown exception in entry point `" + entryPoint + "' for service " << info.name;
- FailureException e(__FILE__, __LINE__);
- e.reason = s.str();
- throw e;
+ throw FailureException(__FILE__, __LINE__, s.str());
}
//
@@ -736,18 +728,14 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint,
s << "ServiceManager: exception while starting service " << info.name << ":\n";
s << ex;
- FailureException e(__FILE__, __LINE__);
- e.reason = s.str();
- throw e;
+ throw FailureException(__FILE__, __LINE__, s.str());
}
catch(...)
{
ostringstream s;
s << "ServiceManager: unknown exception while starting service " << info.name;
- FailureException e(__FILE__, __LINE__);
- e.reason = s.str();
- throw e;
+ throw FailureException(__FILE__, __LINE__, s.str());
}
info.library = library;
diff --git a/cpp/src/IceGrid/Activator.cpp b/cpp/src/IceGrid/Activator.cpp
index 31cbcaf87bb..e53671f934f 100644
--- a/cpp/src/IceGrid/Activator.cpp
+++ b/cpp/src/IceGrid/Activator.cpp
@@ -310,17 +310,14 @@ Activator::Activator(const TraceLevelsPtr& traceLevels) :
if(_hIntr == ICE_NULLPTR)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
+
}
#else
int fds[2];
if(pipe(fds) != 0)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
_fdIntrRead = fds[0];
_fdIntrWrite = fds[1];
@@ -362,13 +359,13 @@ Activator::activate(const string& name,
if(_deactivating)
{
- throw string("The node is being shutdown.");
+ throw runtime_error("The node is being shutdown.");
}
string path = exePath;
if(path.empty())
{
- throw string("The server executable path is empty.");
+ throw invalid_argument("The server executable path is empty.");
}
string pwd = IcePatch2Internal::simplify(pwdPath);
@@ -395,7 +392,7 @@ Activator::activate(const string& name,
Trace out(_traceLevels->logger, _traceLevels->activatorCat);
out << "couldn't find `" << path << "' executable.";
}
- throw string("Couldn't find `" + path + "' executable.");
+ throw runtime_error("Couldn't find `" + path + "' executable.");
}
path = wstringToString(absbuf);
}
@@ -422,7 +419,7 @@ Activator::activate(const string& name,
Trace out(_traceLevels->logger, _traceLevels->activatorCat);
out << "cannot convert `" << pwd << "' into an absolute path";
}
- throw string("The server working directory path `" + pwd + "' can't be converted into an absolute path.");
+ throw runtime_error("The server working directory path `" + pwd + "' can't be converted into an absolute path.");
}
pwd = wstringToString(absbuf);
}
@@ -597,7 +594,7 @@ Activator::activate(const string& name,
if(!b)
{
- throw IceUtilInternal::lastErrorToString();
+ throw runtime_error(IceUtilInternal::lastErrorToString());
}
//
@@ -640,15 +637,13 @@ Activator::activate(const string& name,
}
if(err != 0)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = err;
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, err);
}
else if(pw == 0)
{
ostringstream os;
os << uid;
- throw string("unknown user id `" + os.str() + "'");
+ throw runtime_error("unknown user id `" + os.str() + "'");
}
vector<gid_t> groups;
@@ -671,17 +666,13 @@ Activator::activate(const string& name,
int fds[2];
if(pipe(fds) != 0)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
int errorFds[2];
if(pipe(errorFds) != 0)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
//
@@ -698,9 +689,7 @@ Activator::activate(const string& name,
pid_t pid = fork();
if(pid == -1)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
if(pid == 0) // Child process.
@@ -839,7 +828,7 @@ Activator::activate(const string& name,
close(fds[0]);
close(errorFds[0]);
waitPid(pid);
- throw message;
+ throw runtime_error(message);
}
//
@@ -990,9 +979,7 @@ Activator::sendSignal(const string& name, int signal)
}
else if(GetLastError() != ERROR_INVALID_PARAMETER) // Process with pid doesn't exist anymore.
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
}
else if(signal == SIGKILL)
@@ -1000,9 +987,7 @@ Activator::sendSignal(const string& name, int signal)
HANDLE hnd = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
if(hnd == ICE_NULLPTR)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
TerminateProcess(hnd, 0); // We use 0 for the exit code to make sure it's not considered as a crash.
@@ -1023,9 +1008,7 @@ Activator::sendSignal(const string& name, int signal)
int ret = ::kill(static_cast<pid_t>(pid), signal);
if(ret != 0 && getSystemErrno() != ESRCH)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
if(_traceLevels->activator > 1)
@@ -1186,9 +1169,7 @@ Activator::terminationListener()
DWORD ret = WaitForSingleObject(_hIntr, INFINITE);
if(ret == WAIT_FAILED)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
clearInterrupt();
@@ -1291,9 +1272,7 @@ Activator::terminationListener()
}
#endif
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
vector<Process> terminated;
@@ -1345,9 +1324,7 @@ Activator::terminationListener()
{
if(errno != EAGAIN || message.empty())
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
++p;
@@ -1433,9 +1410,7 @@ Activator::setInterrupt()
ssize_t sz = write(_fdIntrWrite, &c, 1);
if(sz == -1)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno());
}
#endif
}
@@ -1467,9 +1442,7 @@ Activator::waitPid(pid_t processPid)
++nRetry;
continue;
}
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
assert(pid == processPid);
break;
@@ -1478,9 +1451,7 @@ Activator::waitPid(pid_t processPid)
pid_t pid = waitpid(processPid, &status, 0);
if(pid < 0)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSystemErrno());
}
assert(pid == processPid);
#endif
diff --git a/cpp/src/IceGrid/AdminI.cpp b/cpp/src/IceGrid/AdminI.cpp
index 74ca87efb3a..35f30a0c2a8 100644
--- a/cpp/src/IceGrid/AdminI.cpp
+++ b/cpp/src/IceGrid/AdminI.cpp
@@ -659,12 +659,11 @@ AdminI::addObject(const Ice::ObjectPrx& proxy, const ::Ice::Current& current)
{
addObjectWithType(proxy, proxy->ice_id(), current);
}
- catch(const Ice::LocalException& e)
+ catch(const Ice::LocalException& ex)
{
ostringstream os;
-
- os << "failed to invoke ice_id() on proxy `" + current.adapter->getCommunicator()->proxyToString(proxy);
- os << "':\n" << e;
+ os << "failed to invoke ice_id() on proxy `" + current.adapter->getCommunicator()->proxyToString(proxy)
+ << "':\n" << ex;
throw DeploymentException(os.str());
}
}
@@ -682,10 +681,9 @@ AdminI::updateObject(const Ice::ObjectPrx& proxy, const ::Ice::Current&)
const Ice::Identity id = proxy->ice_getIdentity();
if(id.category == _database->getInstanceName())
{
- DeploymentException ex;
- ex.reason = "updating object `" + _database->getCommunicator()->identityToString(id) + "' is not allowed:\n";
- ex.reason += "objects with identity category `" + id.category + "' are managed by IceGrid";
- throw ex;
+ throw DeploymentException("updating object `" + _database->getCommunicator()->identityToString(id) +
+ "' is not allowed:\nobjects with identity category `" + id.category +
+ "' are managed by IceGrid");
}
_database->updateObject(proxy);
}
@@ -703,10 +701,9 @@ AdminI::addObjectWithType(const Ice::ObjectPrx& proxy, const string& type, const
const Ice::Identity id = proxy->ice_getIdentity();
if(id.category == _database->getInstanceName())
{
- DeploymentException ex;
- ex.reason = "adding object `" + _database->getCommunicator()->identityToString(id) + "' is not allowed:\n";
- ex.reason += "objects with identity category `" + id.category + "' are managed by IceGrid";
- throw ex;
+ throw DeploymentException("adding object `" + _database->getCommunicator()->identityToString(id) +
+ "' is not allowed:\nobjects with identity category `" + id.category +
+ "' are managed by IceGrid");
}
ObjectInfo info;
@@ -721,10 +718,9 @@ AdminI::removeObject(const Ice::Identity& id, const Ice::Current&)
checkIsReadOnly();
if(id.category == _database->getInstanceName())
{
- DeploymentException ex;
- ex.reason = "removing object `" + _database->getCommunicator()->identityToString(id) + "' is not allowed:\n";
- ex.reason += "objects with identity category `" + id.category + "' are managed by IceGrid";
- throw ex;
+ throw DeploymentException("removing object `" + _database->getCommunicator()->identityToString(id) +
+ "' is not allowed:\nobjects with identity category `" + id.category +
+ "' are managed by IceGrid");
}
_database->removeObject(id);
}
@@ -983,8 +979,6 @@ AdminI::checkIsReadOnly() const
{
if(_database->isReadOnly())
{
- DeploymentException ex;
- ex.reason = "this operation is not allowed on a slave or read-only master registry.";
- throw ex;
+ throw DeploymentException("this operation is not allowed on a slave or read-only master registry.");
}
}
diff --git a/cpp/src/IceGrid/AdminSessionI.cpp b/cpp/src/IceGrid/AdminSessionI.cpp
index 4a7032b5011..cf3f5ab9f60 100644
--- a/cpp/src/IceGrid/AdminSessionI.cpp
+++ b/cpp/src/IceGrid/AdminSessionI.cpp
@@ -173,9 +173,7 @@ AdminSessionI::setObservers(const RegistryObserverPrx& registryObserver,
Lock sync(*this);
if(_destroyed)
{
- Ice::ObjectNotExistException ex(__FILE__, __LINE__);
- ex.id = current.id;
- throw ex;
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__, current.id, "", "");
}
const int t = _timeout * 1000;
@@ -242,9 +240,7 @@ AdminSessionI::setObserversByIdentity(const Ice::Identity& registryObserver,
Lock sync(*this);
if(_destroyed)
{
- Ice::ObjectNotExistException ex(__FILE__, __LINE__);
- ex.id = current.id;
- throw ex;
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__, current.id, "", "");
}
setupObserverSubscription(RegistryObserverTopicName, addForwarder(registryObserver, current), true);
@@ -260,9 +256,7 @@ AdminSessionI::startUpdate(const Ice::Current& current)
Lock sync(*this);
if(_destroyed)
{
- Ice::ObjectNotExistException ex(__FILE__, __LINE__);
- ex.id = current.id;
- throw ex;
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__, current.id, "", "");
}
int serial = _database->lock(this, _id);
@@ -275,9 +269,7 @@ AdminSessionI::finishUpdate(const Ice::Current& current)
Lock sync(*this);
if(_destroyed)
{
- Ice::ObjectNotExistException ex(__FILE__, __LINE__);
- ex.id = current.id;
- throw ex;
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__, current.id, "", "");
}
_database->unlock(this);
@@ -424,14 +416,13 @@ AdminSessionI::addForwarder(const Ice::ObjectPrx& prx)
}
FileIteratorPrx
-AdminSessionI::addFileIterator(const FileReaderPrx& reader, const string& filename, int nLines, const Ice::Current& c)
+AdminSessionI::addFileIterator(const FileReaderPrx& reader, const string& filename, int nLines,
+ const Ice::Current& current)
{
Lock sync(*this);
if(_destroyed)
{
- Ice::ObjectNotExistException ex(__FILE__, __LINE__);
- ex.id = c.id;
- throw ex;
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__, current.id, "", "");
}
//
@@ -542,9 +533,7 @@ AdminSessionFactory::createGlacier2Session(const string& sessionId, const Glacie
Ice::Warning out(_database->getTraceLevels()->logger);
out << "Failed to callback Glacier2 session control object:\n" << e;
- Glacier2::CannotCreateSessionException ex;
- ex.reason = "internal server error";
- throw ex;
+ throw Glacier2::CannotCreateSessionException("internal server error");
}
}
@@ -591,15 +580,12 @@ AdminSSLSessionManagerI::create(const Glacier2::SSLInfo& info,
IceSSL::CertificatePtr cert = IceSSL::Certificate::decode(info.certs[0]);
userDN = cert->getSubjectDN();
}
- catch(const Ice::Exception& e)
+ catch(const Ice::Exception& ex)
{
// This shouldn't happen, the SSLInfo is supposed to be encoded by Glacier2.
Ice::Error out(_factory->getTraceLevels()->logger);
- out << "SSL session manager couldn't decode SSL certificates:\n" << e;
-
- Glacier2::CannotCreateSessionException ex;
- ex.reason = "internal server error";
- throw ex;
+ out << "SSL session manager couldn't decode SSL certificates:\n" << ex;
+ throw Glacier2::CannotCreateSessionException("internal server error");
}
}
diff --git a/cpp/src/IceGrid/Database.cpp b/cpp/src/IceGrid/Database.cpp
index 00ceef6b4bb..99e6c761b85 100644
--- a/cpp/src/IceGrid/Database.cpp
+++ b/cpp/src/IceGrid/Database.cpp
@@ -667,7 +667,7 @@ Database::addApplication(const ApplicationInfo& info, AdminSessionI* session, Ic
}
}
}
- catch(const DeploymentException& ex)
+ catch(const DeploymentException&)
{
try
{
@@ -695,7 +695,7 @@ Database::addApplication(const ApplicationInfo& info, AdminSessionI* session, Ic
_applicationObserverTopic->waitForSyncedSubscribers(serial);
for_each(entries.begin(), entries.end(), IceUtil::voidMemFun(&ServerEntry::waitForSyncNoThrow));
finishUpdating(info.descriptor.name);
- throw ex;
+ throw;
}
}
@@ -1127,10 +1127,9 @@ Database::removeAdapter(const string& adapterId)
if(_adapterCache.has(adapterId))
{
AdapterEntryPtr adpt = _adapterCache.get(adapterId);
- DeploymentException ex;
- ex.reason = "removing adapter `" + adapterId + "' is not allowed:\n";
- ex.reason += "the adapter was added with the application descriptor `" + adpt->getApplication() + "'";
- throw ex;
+ throw DeploymentException("removing adapter `" + adapterId + "' is not allowed:\n" +
+ "the adapter was added with the application descriptor `" +
+ adpt->getApplication() + "'");
}
AdapterInfoSeq infos;
@@ -1561,12 +1560,9 @@ Database::removeObject(const Ice::Identity& id, Ice::Long dbSerial)
Lock sync(*this);
if(_objectCache.has(id))
{
- DeploymentException ex;
- ex.reason = "removing object `" + _communicator->identityToString(id) + "' is not allowed:\n";
- ex.reason += "the object was added with the application descriptor `";
- ex.reason += _objectCache.get(id)->getApplication();
- ex.reason += "'";
- throw ex;
+ throw DeploymentException("removing object `" + _communicator->identityToString(id) + "' is not allowed:\n"
+ + "the object was added with the application descriptor `" +
+ _objectCache.get(id)->getApplication());
}
try
@@ -1576,9 +1572,7 @@ Database::removeObject(const Ice::Identity& id, Ice::Long dbSerial)
ObjectInfo info;
if(!_objects.get(txn, id, info))
{
- ObjectNotRegisteredException ex;
- ex.id = id;
- throw ex;
+ throw ObjectNotRegisteredException(id);
}
deleteObject(txn, info, false);
dbSerial = updateSerial(txn, objectsDbName, dbSerial);
@@ -1614,12 +1608,9 @@ Database::updateObject(const Ice::ObjectPrx& proxy)
const Ice::Identity id = proxy->ice_getIdentity();
if(_objectCache.has(id))
{
- DeploymentException ex;
- ex.reason = "updating object `" + _communicator->identityToString(id) + "' is not allowed:\n";
- ex.reason += "the object was added with the application descriptor `";
- ex.reason += _objectCache.get(id)->getApplication();
- ex.reason += "'";
- throw ex;
+ throw DeploymentException("updating object `" + _communicator->identityToString(id) + "' is not allowed:\n"
+ + "the object was added with the application descriptor `" +
+ _objectCache.get(id)->getApplication() + "'");
}
ObjectInfo info;
@@ -1630,9 +1621,7 @@ Database::updateObject(const Ice::ObjectPrx& proxy)
if(!_objects.get(txn, id, info))
{
- ObjectNotRegisteredException ex;
- ex.id = id;
- throw ex;
+ ObjectNotRegisteredException(id);
}
info.proxy = proxy;
addObject(txn, info, false);
@@ -1729,9 +1718,7 @@ Database::getObjectProxy(const Ice::Identity& id)
ObjectInfo info;
if(!_objects.get(txn, id, info))
{
- ObjectNotRegisteredException ex;
- ex.id = id;
- throw ex;
+ throw ObjectNotRegisteredException(id);
}
return info.proxy;
}
@@ -1911,9 +1898,7 @@ Database::removeInternalObject(const Ice::Identity& id)
ObjectInfo info;
if(!_internalObjects.get(txn, id, info))
{
- ObjectNotRegisteredException ex;
- ex.id = id;
- throw ex;
+ throw ObjectNotRegisteredException(id);
}
deleteObject(txn, info, true);
@@ -2026,9 +2011,7 @@ Database::checkForUpdate(const ApplicationHelper& origApp,
back_inserter(invalidAdptRepGrps));
if(!invalidAdptRepGrps.empty())
{
- DeploymentException ex;
- ex.reason = "couldn't find replica group `" + invalidAdptRepGrps.front() + "'";
- throw ex;
+ throw DeploymentException("couldn't find replica group `" + invalidAdptRepGrps.front() + "'");
}
}
@@ -2046,9 +2029,7 @@ Database::checkServerForAddition(const string& id)
{
if(_serverCache.has(id))
{
- DeploymentException ex;
- ex.reason = "server `" + id + "' is already registered";
- throw ex;
+ throw DeploymentException("server `" + id + "' is already registered");
}
}
@@ -2077,9 +2058,7 @@ Database::checkAdapterForAddition(const string& id, const IceDB::ReadWriteTxn& t
if(found)
{
- DeploymentException ex;
- ex.reason = "adapter `" + id + "' is already registered";
- throw ex;
+ throw DeploymentException("adapter `" + id + "' is already registered");
}
}
@@ -2102,9 +2081,7 @@ Database::checkObjectForAddition(const Ice::Identity& objectId,
if(found)
{
- DeploymentException ex;
- ex.reason = "object `" + _communicator->identityToString(objectId) + "' is already registered";
- throw ex;
+ throw DeploymentException("object `" + _communicator->identityToString(objectId) + "' is already registered");
}
}
@@ -2122,9 +2099,7 @@ Database::checkReplicaGroupExists(const string& replicaGroup)
if(!entry)
{
- DeploymentException ex;
- ex.reason = "couldn't find replica group `" + replicaGroup + "'";
- throw ex;
+ throw DeploymentException("couldn't find replica group `" + replicaGroup + "'");
}
}
@@ -2152,10 +2127,8 @@ Database::checkReplicaGroupForRemove(const string& replicaGroup)
if(entry->hasAdaptersFromOtherApplications())
{
- DeploymentException ex;
- ex.reason = "couldn't remove application because the replica group `" + replicaGroup +
- "' is used by object adapters from other applications.";
- throw ex;
+ throw DeploymentException("couldn't remove application because the replica group `" + replicaGroup +
+ "' is used by object adapters from other applications.");
}
}
@@ -2628,7 +2601,7 @@ Database::finishApplicationUpdate(const ApplicationUpdateInfo& update,
}
}
}
- catch(const DeploymentException& ex)
+ catch(const DeploymentException&)
{
ApplicationUpdateInfo newUpdate;
{
@@ -2669,7 +2642,7 @@ Database::finishApplicationUpdate(const ApplicationUpdateInfo& update,
_applicationObserverTopic->waitForSyncedSubscribers(serial); // Wait for subscriber to be updated.
for_each(entries.begin(), entries.end(), IceUtil::voidMemFun(&ServerEntry::waitForSyncNoThrow));
finishUpdating(newDesc.name);
- throw ex;
+ throw;
}
}
diff --git a/cpp/src/IceGrid/DescriptorBuilder.cpp b/cpp/src/IceGrid/DescriptorBuilder.cpp
index f7513cf49c6..d1de8a18c50 100644
--- a/cpp/src/IceGrid/DescriptorBuilder.cpp
+++ b/cpp/src/IceGrid/DescriptorBuilder.cpp
@@ -44,7 +44,7 @@ XmlAttributesHelper::checkUnknownAttributes()
{
ostringstream os;
os << "unknown attributes in <" << _filename << "> descriptor, line " << _line << ":\n" << toString(notUsed);
- throw os.str();
+ throw invalid_argument(os.str());
}
}
@@ -62,12 +62,12 @@ XmlAttributesHelper::operator()(const string& name) const
IceXML::Attributes::const_iterator p = _attributes.find(name);
if(p == _attributes.end())
{
- throw "missing attribute '" + name + "'";
+ throw invalid_argument("missing attribute '" + name + "'");
}
string v = p->second;
if(v.empty())
{
- throw "attribute '" + name + "' is empty";
+ throw invalid_argument("attribute '" + name + "' is empty");
}
return v;
}
@@ -104,7 +104,7 @@ XmlAttributesHelper::asBool(const string& name) const
IceXML::Attributes::const_iterator p = _attributes.find(name);
if(p == _attributes.end())
{
- throw "missing attribute '" + name + "'";
+ throw invalid_argument("missing attribute '" + name + "'");
return true; // Keep the compiler happy.
}
else if(p->second == "true")
@@ -117,7 +117,7 @@ XmlAttributesHelper::asBool(const string& name) const
}
else
{
- throw "invalid attribute `" + name + "': value is not 'false' or 'true'";
+ throw invalid_argument("invalid attribute `" + name + "': value is not 'false' or 'true'");
return true; // Keep the compiler happy.
}
}
@@ -141,7 +141,7 @@ XmlAttributesHelper::asBool(const string& name, bool def) const
}
else
{
- throw "invalid attribute `" + name + "': value is not 'false' or 'true'";
+ throw invalid_argument("invalid attribute `" + name + "': value is not 'false' or 'true'");
return true; // Keep the compiler happy.
}
}
@@ -149,7 +149,7 @@ XmlAttributesHelper::asBool(const string& name, bool def) const
void
DescriptorBuilder::addVariable(const XmlAttributesHelper&)
{
- throw "the <variable> element can't be a child of this element";
+ throw invalid_argument("the <variable> element can't be a child of this element");
}
PropertySetDescriptorBuilder::PropertySetDescriptorBuilder() :
@@ -202,11 +202,11 @@ PropertySetDescriptorBuilder::addPropertySet(const XmlAttributesHelper& attrs)
{
if(attrs.contains("id") || !attrs.contains("refid"))
{
- throw "only <properties refid=\"\"> can be a child of a <properties> element";
+ throw invalid_argument("only <properties refid=\"\"> can be a child of a <properties> element");
}
if(!_descriptor.properties.empty())
{
- throw "<properties refid=\"\"> can't be defined after a <property> element";
+ throw invalid_argument("<properties refid=\"\"> can't be defined after a <property> element");
}
_descriptor.references.push_back(attrs("refid"));
_inPropertySetRef = true;
@@ -302,7 +302,7 @@ ApplicationDescriptorBuilder::setLoadBalancing(const XmlAttributesHelper& attrs)
}
else
{
- throw "invalid load balancing policy `" + type + "'";
+ throw invalid_argument("invalid load balancing policy `" + type + "'");
}
policy->nReplicas = attrs("n-replicas", "1");
_descriptor.replicaGroups.back().loadBalancing = policy;
@@ -323,7 +323,7 @@ ApplicationDescriptorBuilder::addObject(const XmlAttributesHelper& attrs)
object.proxyOptions = attrs("proxy-options", "");
if(attrs.contains("property"))
{
- throw "property attribute is not allowed in object descriptors from a replica group";
+ throw invalid_argument("property attribute is not allowed in object descriptors from a replica group");
}
_descriptor.replicaGroups.back().objects.push_back(object);
}
@@ -380,11 +380,11 @@ ApplicationDescriptorBuilder::addServerTemplate(const string& id, const Template
{
if(!templ.descriptor)
{
- throw "invalid server template `" + id + "': server definition is missing";
+ throw invalid_argument("invalid server template `" + id + "': server definition is missing");
}
if(!_descriptor.serverTemplates.insert(make_pair(id, templ)).second)
{
- throw "duplicate server template `" + id + "'";
+ throw invalid_argument("duplicate server template `" + id + "'");
}
}
@@ -393,11 +393,11 @@ ApplicationDescriptorBuilder::addServiceTemplate(const string& id, const Templat
{
if(!templ.descriptor)
{
- throw "invalid service template `" + id + "': service definition is missing";
+ throw invalid_argument("invalid service template `" + id + "': service definition is missing");
}
if(!_descriptor.serviceTemplates.insert(make_pair(id, templ)).second)
{
- throw "duplicate service template `" + id + "'";
+ throw invalid_argument("duplicate service template `" + id + "'");
}
}
@@ -406,7 +406,7 @@ ApplicationDescriptorBuilder::addPropertySet(const string& id, const PropertySet
{
if(!_descriptor.propertySets.insert(make_pair(id, desc)).second)
{
- throw "duplicate property set `" + id + "'";
+ throw invalid_argument("duplicate property set `" + id + "'");
}
}
@@ -528,7 +528,7 @@ NodeDescriptorBuilder::addPropertySet(const string& id, const PropertySetDescrip
{
if(!_descriptor.propertySets.insert(make_pair(id, desc)).second)
{
- throw "duplicate property set `" + id + "'";
+ throw invalid_argument("duplicate property set `" + id + "'");
}
}
@@ -553,7 +553,7 @@ TemplateDescriptorBuilder::addParameter(const XmlAttributesHelper& attrs)
if(find(_descriptor.parameters.begin(), _descriptor.parameters.end(), attrs("name")) !=
_descriptor.parameters.end())
{
- throw "duplicate parameter `" + attrs("name") + "'";
+ throw invalid_argument("duplicate parameter `" + attrs("name") + "'");
}
_descriptor.parameters.push_back(attrs("name"));
@@ -574,7 +574,7 @@ TemplateDescriptorBuilder::createServer(const XmlAttributesHelper& attrs)
{
if(_serviceTemplate)
{
- throw "<server> element can't be a child of <service-template>";
+ throw invalid_argument("<server> element can't be a child of <service-template>");
}
return new ServerDescriptorBuilder(_application.getCommunicator(), attrs);
}
@@ -584,7 +584,7 @@ TemplateDescriptorBuilder::createIceBox(const XmlAttributesHelper& attrs)
{
if(_serviceTemplate)
{
- throw "<icebox> element can't be a child of <service-template>";
+ throw invalid_argument("<icebox> element can't be a child of <service-template>");
}
return new IceBoxDescriptorBuilder(_application.getCommunicator(), attrs);
}
@@ -594,7 +594,7 @@ TemplateDescriptorBuilder::createService(const XmlAttributesHelper& attrs)
{
if(!_serviceTemplate)
{
- throw "<service> element can't be a child of <server-template>";
+ throw invalid_argument("<service> element can't be a child of <server-template>");
}
return new ServiceDescriptorBuilder(_application.getCommunicator(), attrs);
}
@@ -675,7 +675,7 @@ CommunicatorDescriptorBuilder::addAdapter(const XmlAttributesHelper& attrs)
desc.registerProcess = attrs.asBool("register-process", false);
if(desc.id == "")
{
- throw "empty `id' for adapter `" + desc.name + "'";
+ throw invalid_argument("empty `id' for adapter `" + desc.name + "'");
}
desc.serverLifetime = attrs.asBool("server-lifetime", true);
_descriptor->adapters.push_back(desc);
@@ -762,9 +762,9 @@ CommunicatorDescriptorBuilder::addDbEnvProperty(const XmlAttributesHelper& attrs
{
if(!_descriptor->dbEnvs.back().dbHome.empty())
{
- throw "can't add property to the database environment:\n"
- "properties are only allowed if the database\n"
- "environment home directory is managed by the node";
+ throw invalid_argument("can't add property to the database environment:\n"
+ "properties are only allowed if the database\n"
+ "environment home directory is managed by the node");
}
PropertyDescriptor prop;
@@ -854,14 +854,14 @@ ServerDescriptorBuilder::init(const ServerDescriptorPtr& desc, const XmlAttribut
ServiceDescriptorBuilder*
ServerDescriptorBuilder::createService(const XmlAttributesHelper& /*attrs*/)
{
- throw "<service> element can only be a child of an <icebox> element";
+ throw invalid_argument("<service> element can only be a child of an <icebox> element");
return 0;
}
ServiceInstanceDescriptorBuilder*
ServerDescriptorBuilder::createServiceInstance(const XmlAttributesHelper& /*attrs*/)
{
- throw "<service-instance> element can only be a child of an <icebox> element";
+ throw invalid_argument("<service-instance> element can only be a child of an <icebox> element");
return 0;
}
@@ -930,13 +930,13 @@ IceBoxDescriptorBuilder::createServiceInstance(const XmlAttributesHelper& attrs)
void
IceBoxDescriptorBuilder::addAdapter(const XmlAttributesHelper& /*attrs*/)
{
- throw "<adapter> element can't be a child of an <icebox> element";
+ throw invalid_argument("<adapter> element can't be a child of an <icebox> element");
}
void
IceBoxDescriptorBuilder::addDbEnv(const XmlAttributesHelper& /*attrs*/)
{
- throw "<dbenv> element can't be a child of an <icebox> element";
+ throw invalid_argument("<dbenv> element can't be a child of an <icebox> element");
}
void
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
diff --git a/cpp/src/IceGrid/DescriptorParser.cpp b/cpp/src/IceGrid/DescriptorParser.cpp
index 1a877a16b67..97c009dce31 100644
--- a/cpp/src/IceGrid/DescriptorParser.cpp
+++ b/cpp/src/IceGrid/DescriptorParser.cpp
@@ -194,7 +194,7 @@ DescriptorHandler::startElement(const string& name, const IceXML::Attributes& at
}
catch(const DeploymentException& ex)
{
- throw ex.reason;
+ throw runtime_error(ex.reason);
}
}
else
@@ -468,13 +468,9 @@ DescriptorHandler::startElement(const string& name, const IceXML::Attributes& at
attributes.checkUnknownAttributes();
}
- catch(const string& reason)
+ catch(const exception& ex)
{
- error(reason);
- }
- catch(const char* reason)
- {
- error(reason);
+ error(ex.what());
}
//
@@ -690,13 +686,9 @@ DescriptorHandler::endElement(const string& name, int line, int column)
_inDistrib = false;
}
}
- catch(const string& reason)
- {
- error(reason);
- }
- catch(const char* reason)
+ catch(const exception& ex)
{
- error(reason);
+ error(ex.what());
}
//
diff --git a/cpp/src/IceGrid/FileUserAccountMapperI.cpp b/cpp/src/IceGrid/FileUserAccountMapperI.cpp
index bc27c667fda..ef485fdf3e6 100644
--- a/cpp/src/IceGrid/FileUserAccountMapperI.cpp
+++ b/cpp/src/IceGrid/FileUserAccountMapperI.cpp
@@ -20,7 +20,7 @@ FileUserAccountMapperI::FileUserAccountMapperI(const string& filename)
ifstream file(IceUtilInternal::streamFilename(filename).c_str()); // filename is a UTF-8 string
if(!file)
{
- throw "cannot open `" + filename + "' for reading: " + strerror(errno);
+ throw runtime_error("cannot open `" + filename + "' for reading: " + strerror(errno));
}
const string delim = " \t\r\n";
diff --git a/cpp/src/IceGrid/IceGridNode.cpp b/cpp/src/IceGrid/IceGridNode.cpp
index 129b2f3378c..5ee61ccbc10 100644
--- a/cpp/src/IceGrid/IceGridNode.cpp
+++ b/cpp/src/IceGrid/IceGridNode.cpp
@@ -98,23 +98,17 @@ private:
#ifdef _WIN32
void
-setNoIndexingAttribute(const string& pa)
+setNoIndexingAttribute(const string& path)
{
- wstring path = Ice::stringToWstring(pa);
- DWORD attrs = GetFileAttributesW(path.c_str());
+ wstring wpath = Ice::stringToWstring(path);
+ DWORD attrs = GetFileAttributesW(wpath.c_str());
if(attrs == INVALID_FILE_ATTRIBUTES)
{
- FileException ex(__FILE__, __LINE__);
- ex.path = pa;
- ex.error = IceInternal::getSystemErrno();
- throw ex;
+ throw FileException(__FILE__, __LINE__, IceInternal::getSystemErrno(), path);
}
- if(!SetFileAttributesW(path.c_str(), attrs | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED))
+ if(!SetFileAttributesW(wpath.c_str(), attrs | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED))
{
- FileException ex(__FILE__, __LINE__);
- ex.path = pa;
- ex.error = IceInternal::getSystemErrno();
- throw ex;
+ throw FileException(__FILE__, __LINE__, IceInternal::getSystemErrno(), path);
}
}
#endif
@@ -339,10 +333,7 @@ NodeService::startImpl(int argc, char* argv[], int& status)
{
if(!IceUtilInternal::directoryExists(dataPath))
{
- FileException ex(__FILE__, __LINE__);
- ex.path = dataPath;
- ex.error = IceInternal::getSystemErrno();
-
+ FileException ex(__FILE__, __LINE__, IceInternal::getSystemErrno(), dataPath);
ServiceError err(this);
err << "property `IceGrid.Node.Data' is set to an invalid path:\n" << ex;
return false;
@@ -427,9 +418,9 @@ NodeService::startImpl(int argc, char* argv[], int& status)
Ice::ObjectPrx object = _adapter->addWithUUID(new FileUserAccountMapperI(userAccountFileProperty));
mapper = UserAccountMapperPrx::uncheckedCast(object);
}
- catch(const std::string& msg)
+ catch(const exception& ex)
{
- error(msg);
+ error(ex.what());
return false;
}
}
@@ -559,7 +550,7 @@ NodeService::startImpl(int argc, char* argv[], int& status)
RegistryPrx registry = RegistryPrx::checkedCast(communicator()->getDefaultLocator()->findObjectById(regId));
if(!registry)
{
- throw "invalid registry";
+ throw runtime_error("invalid registry");
}
registry = registry->ice_preferSecure(true); // Use SSL if available.
@@ -618,12 +609,7 @@ NodeService::startImpl(int argc, char* argv[], int& status)
catch(const std::exception& ex)
{
ServiceWarning warn(this);
- warn << "failed to deploy application `" << desc << "':\n" << ex;
- }
- catch(const string& reason)
- {
- ServiceWarning warn(this);
- warn << "failed to deploy application `" << desc << "':\n" << reason;
+ warn << "failed to deploy application `" << desc << "':\n" << ex.what();
}
}
diff --git a/cpp/src/IceGrid/InternalRegistryI.cpp b/cpp/src/IceGrid/InternalRegistryI.cpp
index d5a62e7c512..6490c35717c 100644
--- a/cpp/src/IceGrid/InternalRegistryI.cpp
+++ b/cpp/src/IceGrid/InternalRegistryI.cpp
@@ -90,9 +90,9 @@ InternalRegistryI::registerNode(const InternalNodeInfoPtr& info,
throw PermissionDeniedException("node certificate is required to connect to this registry");
}
}
- catch(const PermissionDeniedException& ex)
+ catch(const PermissionDeniedException&)
{
- throw ex;
+ throw;
}
catch(const IceUtil::Exception&)
{
@@ -157,9 +157,9 @@ InternalRegistryI::registerReplica(const InternalReplicaInfoPtr& info,
throw PermissionDeniedException("replica certificate is required to connect to this registry");
}
}
- catch(const PermissionDeniedException& ex)
+ catch(const PermissionDeniedException&)
{
- throw ex;
+ throw;
}
catch(const IceUtil::Exception&)
{
diff --git a/cpp/src/IceGrid/NodeCache.cpp b/cpp/src/IceGrid/NodeCache.cpp
index 6acb54222d7..041d9e08a9d 100644
--- a/cpp/src/IceGrid/NodeCache.cpp
+++ b/cpp/src/IceGrid/NodeCache.cpp
@@ -327,9 +327,7 @@ NodeCache::get(const string& name, bool create) const
}
if(!entry)
{
- NodeNotExistException ex;
- ex.name = name;
- throw ex;
+ throw NodeNotExistException(name);
}
return entry;
}
diff --git a/cpp/src/IceGrid/NodeI.cpp b/cpp/src/IceGrid/NodeI.cpp
index b796dab7d78..3a74ae62e45 100644
--- a/cpp/src/IceGrid/NodeI.cpp
+++ b/cpp/src/IceGrid/NodeI.cpp
@@ -586,11 +586,11 @@ NodeI::patch_async(const AMD_Node_patchPtr& amdCB,
{
if(running.size() == 1)
{
- throw "server `" + toString(running) + "' is active";
+ throw runtime_error("server `" + toString(running) + "' is active");
}
else
{
- throw "servers `" + toString(running, ", ") + "' are active";
+ throw runtime_error("servers `" + toString(running, ", ") + "' are active");
}
}
@@ -609,7 +609,7 @@ NodeI::patch_async(const AMD_Node_patchPtr& amdCB,
icepatch = FileServerPrx::checkedCast(_communicator->stringToProxy(appDistrib->icepatch));
if(!icepatch)
{
- throw "proxy `" + appDistrib->icepatch + "' is not a file server.";
+ throw runtime_error("proxy `" + appDistrib->icepatch + "' is not a file server.");
}
patch(icepatch, "distrib/" + application, appDistrib->directories);
}
@@ -625,7 +625,7 @@ NodeI::patch_async(const AMD_Node_patchPtr& amdCB,
icepatch = FileServerPrx::checkedCast(_communicator->stringToProxy(dist->icepatch));
if(!icepatch)
{
- throw "proxy `" + dist->icepatch + "' is not a file server.";
+ throw runtime_error("proxy `" + dist->icepatch + "' is not a file server.");
}
patch(icepatch, "servers/" + (*s)->getId() + "/distrib", dist->directories);
@@ -636,19 +636,9 @@ NodeI::patch_async(const AMD_Node_patchPtr& amdCB,
}
}
}
- catch(const Ice::LocalException& e)
+ catch(const exception& ex)
{
- ostringstream os;
- os << e;
- failure = os.str();
- }
- catch(const string& e)
- {
- failure = e;
- }
- catch(const char* e)
- {
- failure = e;
+ failure = ex.what();
}
for(set<ServerIPtr>::const_iterator s = servers.begin(); s != servers.end(); ++s)
@@ -1078,10 +1068,10 @@ NodeI::removeServer(const ServerIPtr& server, const std::string& application)
{
IcePatch2Internal::removeRecursive(appDir);
}
- catch(const string& msg)
+ catch(const exception& ex)
{
Ice::Warning out(_traceLevels->logger);
- out << "removing application directory `" << appDir << "' failed:\n" << msg;
+ out << "removing application directory `" << appDir << "' failed:\n" << ex.what();
}
}
}
@@ -1117,10 +1107,10 @@ NodeI::checkConsistencyNoSync(const Ice::StringSeq& servers)
{
contents = readDirectory(_serversDir);
}
- catch(const string& msg)
+ catch(const exception& ex)
{
Ice::Error out(_traceLevels->logger);
- out << "couldn't read directory `" << _serversDir << "':\n" << msg;
+ out << "couldn't read directory `" << _serversDir << "':\n" << ex.what();
return commands;
}
@@ -1156,7 +1146,7 @@ NodeI::checkConsistencyNoSync(const Ice::StringSeq& servers)
Ice::Error out(_traceLevels->logger);
out << "server `" << *p << "' destroy failed:\n" << ex;
}
- catch(const string&)
+ catch(const exception&)
{
assert(false);
}
@@ -1175,10 +1165,10 @@ NodeI::checkConsistencyNoSync(const Ice::StringSeq& servers)
continue;
}
}
- catch(const string& msg)
+ catch(const exception& ex)
{
Ice::Warning out(_traceLevels->logger);
- out << "removing server directory `" << _serversDir << "/" << *p << "' failed:\n" << msg;
+ out << "removing server directory `" << _serversDir << "/" << *p << "' failed:\n" << ex.what();
}
*p = _serversDir + "/" + *p;
@@ -1260,7 +1250,7 @@ NodeI::canRemoveServerDirectory(const string& name)
return false;
}
}
- catch(const string&)
+ catch(const exception&)
{
return false;
}
@@ -1284,7 +1274,7 @@ NodeI::canRemoveServerDirectory(const string& name)
return false;
}
}
- catch(const string&)
+ catch(const exception&)
{
return false;
}
diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp
index 81ab1d9de49..8b3562acdbf 100644
--- a/cpp/src/IceGrid/Parser.cpp
+++ b/cpp/src/IceGrid/Parser.cpp
@@ -499,7 +499,7 @@ Parser::checkInterrupted()
Lock sync(*this);
if(_interrupted)
{
- throw "interrupted with Ctrl-C";
+ throw runtime_error("interrupted with Ctrl-C");
}
}
}
diff --git a/cpp/src/IceGrid/PlatformInfo.cpp b/cpp/src/IceGrid/PlatformInfo.cpp
index 0671f100cb7..d20b431e621 100644
--- a/cpp/src/IceGrid/PlatformInfo.cpp
+++ b/cpp/src/IceGrid/PlatformInfo.cpp
@@ -228,9 +228,7 @@ PlatformInfo::PlatformInfo(const string& prefix,
size_t sz = sizeof(_nProcessorThreads);
if(sysctl(ncpu, 2, &_nProcessorThreads, &sz, 0, 0) == -1)
{
- Ice::SyscallException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSystemErrno();
- throw ex;
+ throw Ice::SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno());
}
#else
_nProcessorThreads = static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
@@ -392,7 +390,7 @@ PlatformInfo::PlatformInfo(const string& prefix,
string cwd;
if(IceUtilInternal::getcwd(cwd) != 0)
{
- throw "cannot get the current directory:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot get the current directory:\n" + IceUtilInternal::lastErrorToString());
}
_cwd = string(cwd);
diff --git a/cpp/src/IceGrid/RegistryI.cpp b/cpp/src/IceGrid/RegistryI.cpp
index 42601b43e1f..cfe14e0e9b4 100644
--- a/cpp/src/IceGrid/RegistryI.cpp
+++ b/cpp/src/IceGrid/RegistryI.cpp
@@ -346,9 +346,7 @@ RegistryI::startImpl()
{
if(!IceUtilInternal::directoryExists(dbPath))
{
- Ice::SyscallException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSystemErrno();
-
+ Ice::SyscallException ex(__FILE__, __LINE__, IceInternal::getSystemErrno());
Ice::Error out(_communicator->getLogger());
out << "property `IceGrid.Registry.LMDB.Path' is set to an invalid path:\n" << ex;
return false;
@@ -937,27 +935,21 @@ RegistryI::createSession(const string& user, const string& password, const Curre
{
if(!_master)
{
- PermissionDeniedException ex;
- ex.reason = "client session creation is only allowed with the master registry.";
- throw ex;
+ throw PermissionDeniedException("client session creation is only allowed with the master registry.");
}
assert(_reaper && _clientSessionFactory);
if(!_clientVerifier)
{
- PermissionDeniedException ex;
- ex.reason = "no permissions verifier configured, use the property\n";
- ex.reason += "`IceGrid.Registry.PermissionsVerifier' to configure\n";
- ex.reason += "a permissions verifier.";
- throw ex;
+ throw PermissionDeniedException("no permissions verifier configured, use the property\n"
+ "`IceGrid.Registry.PermissionsVerifier' to configure\n"
+ "a permissions verifier.");
}
if(user.empty())
{
- PermissionDeniedException ex;
- ex.reason = "empty user id";
- throw ex;
+ throw PermissionDeniedException("empty user id");
}
try
@@ -965,16 +957,12 @@ RegistryI::createSession(const string& user, const string& password, const Curre
string reason;
if(!_clientVerifier->checkPermissions(user, password, reason, current.ctx))
{
- PermissionDeniedException exc;
- exc.reason = reason;
- throw exc;
+ throw PermissionDeniedException(reason);
}
}
catch(const Glacier2::PermissionDeniedException& ex)
{
- PermissionDeniedException exc;
- exc.reason = ex.reason;
- throw exc;
+ throw PermissionDeniedException(ex.reason);
}
catch(const LocalException& ex)
{
@@ -984,9 +972,7 @@ RegistryI::createSession(const string& user, const string& password, const Curre
out << "exception while verifying password with client permission verifier:\n" << ex;
}
- PermissionDeniedException exc;
- exc.reason = "internal server error";
- throw exc;
+ throw PermissionDeniedException("internal server error");
}
SessionIPtr session = _clientSessionFactory->createSessionServant(user, 0);
@@ -1003,18 +989,14 @@ RegistryI::createAdminSession(const string& user, const string& password, const
if(!_adminVerifier)
{
- PermissionDeniedException ex;
- ex.reason = "no admin permissions verifier configured, use the property\n";
- ex.reason += "`IceGrid.Registry.AdminPermissionsVerifier' to configure\n";
- ex.reason += "a permissions verifier.";
- throw ex;
+ throw PermissionDeniedException("no admin permissions verifier configured, use the property\n"
+ "`IceGrid.Registry.AdminPermissionsVerifier' to configure\n"
+ "a permissions verifier.");
}
if(user.empty())
{
- PermissionDeniedException ex;
- ex.reason = "empty user id";
- throw ex;
+ throw PermissionDeniedException("empty user id");
}
try
@@ -1022,16 +1004,12 @@ RegistryI::createAdminSession(const string& user, const string& password, const
string reason;
if(!_adminVerifier->checkPermissions(user, password, reason, current.ctx))
{
- PermissionDeniedException exc;
- exc.reason = reason;
- throw exc;
+ throw PermissionDeniedException(reason);
}
}
catch(const Glacier2::PermissionDeniedException& ex)
{
- PermissionDeniedException exc;
- exc.reason = ex.reason;
- throw exc;
+ throw PermissionDeniedException(ex.reason);
}
catch(const LocalException& ex)
{
@@ -1041,9 +1019,7 @@ RegistryI::createAdminSession(const string& user, const string& password, const
out << "exception while verifying password with admin permission verifier:\n" << ex;
}
- PermissionDeniedException exc;
- exc.reason = "internal server error";
- throw exc;
+ throw PermissionDeniedException("internal server error");
}
AdminSessionIPtr session = _adminSessionFactory->createSessionServant(user);
@@ -1058,29 +1034,23 @@ RegistryI::createSessionFromSecureConnection(const Current& current)
{
if(!_master)
{
- PermissionDeniedException ex;
- ex.reason = "client session creation is only allowed with the master registry.";
- throw ex;
+ throw PermissionDeniedException("client session creation is only allowed with the master registry.");
}
assert(_reaper && _clientSessionFactory);
if(!_sslClientVerifier)
{
- PermissionDeniedException ex;
- ex.reason = "no ssl permissions verifier configured, use the property\n";
- ex.reason += "`IceGrid.Registry.SSLPermissionsVerifier' to configure\n";
- ex.reason += "a permissions verifier.";
- throw ex;
+ throw PermissionDeniedException("no ssl permissions verifier configured, use the property\n"
+ "`IceGrid.Registry.SSLPermissionsVerifier' to configure\n"
+ "a permissions verifier.");
}
string userDN;
Glacier2::SSLInfo info = getSSLInfo(current.con, userDN);
if(userDN.empty())
{
- PermissionDeniedException ex;
- ex.reason = "empty user DN";
- throw ex;
+ throw PermissionDeniedException("empty user DN");
}
try
@@ -1088,16 +1058,12 @@ RegistryI::createSessionFromSecureConnection(const Current& current)
string reason;
if(!_sslClientVerifier->authorize(info, reason, current.ctx))
{
- PermissionDeniedException exc;
- exc.reason = reason;
- throw exc;
+ throw PermissionDeniedException(reason);
}
}
catch(const Glacier2::PermissionDeniedException& ex)
{
- PermissionDeniedException exc;
- exc.reason = ex.reason;
- throw exc;
+ throw PermissionDeniedException(ex.reason);
}
catch(const LocalException& ex)
{
@@ -1107,9 +1073,7 @@ RegistryI::createSessionFromSecureConnection(const Current& current)
out << "exception while verifying password with SSL client permission verifier:\n" << ex;
}
- PermissionDeniedException exc;
- exc.reason = "internal server error";
- throw exc;
+ throw PermissionDeniedException("internal server error");
}
SessionIPtr session = _clientSessionFactory->createSessionServant(userDN, 0);
@@ -1126,11 +1090,9 @@ RegistryI::createAdminSessionFromSecureConnection(const Current& current)
if(!_sslAdminVerifier)
{
- PermissionDeniedException ex;
- ex.reason = "no ssl admin permissions verifier configured, use the property\n";
- ex.reason += "`IceGrid.Registry.AdminSSLPermissionsVerifier' to configure\n";
- ex.reason += "a permissions verifier.";
- throw ex;
+ throw PermissionDeniedException("no ssl admin permissions verifier configured, use the property\n"
+ "`IceGrid.Registry.AdminSSLPermissionsVerifier' to configure\n"
+ "a permissions verifier.");
}
string userDN;
@@ -1140,16 +1102,12 @@ RegistryI::createAdminSessionFromSecureConnection(const Current& current)
string reason;
if(!_sslAdminVerifier->authorize(info, reason, current.ctx))
{
- PermissionDeniedException exc;
- exc.reason = reason;
- throw exc;
+ throw PermissionDeniedException(reason);
}
}
catch(const Glacier2::PermissionDeniedException& ex)
{
- PermissionDeniedException exc;
- exc.reason = ex.reason;
- throw exc;
+ throw PermissionDeniedException(ex.reason);
}
catch(const LocalException& ex)
{
@@ -1159,9 +1117,7 @@ RegistryI::createAdminSessionFromSecureConnection(const Current& current)
out << "exception while verifying password with SSL admin permission verifier:\n" << ex;
}
- PermissionDeniedException exc;
- exc.reason = "internal server error";
- throw exc;
+ throw PermissionDeniedException("internal server error");
}
//
@@ -1346,9 +1302,7 @@ RegistryI::getSSLInfo(const ConnectionPtr& connection, string& userDN)
IceSSL::ConnectionInfoPtr info = IceSSL::ConnectionInfoPtr::dynamicCast(connection->getInfo());
if(!info)
{
- PermissionDeniedException exc;
- exc.reason = "not ssl connection";
- throw exc;
+ throw PermissionDeniedException("not ssl connection");
}
Ice::IPConnectionInfoPtr ipInfo = getIPConnectionInfo(info);
@@ -1368,15 +1322,11 @@ RegistryI::getSSLInfo(const ConnectionPtr& connection, string& userDN)
}
catch(const IceSSL::CertificateEncodingException&)
{
- PermissionDeniedException exc;
- exc.reason = "certificate encoding exception";
- throw exc;
+ throw PermissionDeniedException("certificate encoding exception");
}
catch(const Ice::LocalException&)
{
- PermissionDeniedException exc;
- exc.reason = "connection exception";
- throw exc;
+ throw PermissionDeniedException("connection exception");
}
return sslinfo;
diff --git a/cpp/src/IceGrid/ReplicaCache.cpp b/cpp/src/IceGrid/ReplicaCache.cpp
index 3f9ab61240d..2444fdad919 100644
--- a/cpp/src/IceGrid/ReplicaCache.cpp
+++ b/cpp/src/IceGrid/ReplicaCache.cpp
@@ -155,9 +155,7 @@ ReplicaCache::get(const string& name) const
ReplicaEntryPtr entry = getImpl(name);
if(!entry)
{
- RegistryNotExistException ex;
- ex.name = name;
- throw ex;
+ throw RegistryNotExistException(name);
}
return entry;
}
diff --git a/cpp/src/IceGrid/ServerAdapterI.cpp b/cpp/src/IceGrid/ServerAdapterI.cpp
index 879ffc6c2b8..fc9fd904dd2 100644
--- a/cpp/src/IceGrid/ServerAdapterI.cpp
+++ b/cpp/src/IceGrid/ServerAdapterI.cpp
@@ -122,9 +122,7 @@ ServerAdapterI::getDirectProxy(const Ice::Current&) const
}
else
{
- AdapterNotActiveException ex;
- ex.activatable = _enabled && _server->isAdapterActivatable(_id);
- throw ex;
+ throw AdapterNotActiveException(_enabled && _server->isAdapterActivatable(_id));
}
}
diff --git a/cpp/src/IceGrid/ServerCache.cpp b/cpp/src/IceGrid/ServerCache.cpp
index ad4e264df12..1b10dbfd89b 100644
--- a/cpp/src/IceGrid/ServerCache.cpp
+++ b/cpp/src/IceGrid/ServerCache.cpp
@@ -162,9 +162,7 @@ ServerCache::get(const string& id) const
ServerEntryPtr entry = getImpl(id);
if(!entry)
{
- ServerNotExistException ex;
- ex.id = id;
- throw ex;
+ throw ServerNotExistException(id);
}
return entry;
}
diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp
index dd06b2932b7..f087054f643 100644
--- a/cpp/src/IceGrid/ServerI.cpp
+++ b/cpp/src/IceGrid/ServerI.cpp
@@ -49,7 +49,7 @@ chownRecursive(const string& path, uid_t uid, gid_t gid)
DIR* d;
if((d = opendir(path.c_str())) == 0)
{
- throw "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
struct dirent* entry;
@@ -66,7 +66,7 @@ chownRecursive(const string& path, uid_t uid, gid_t gid)
if(closedir(d))
{
- throw "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
for(size_t i = 0; i < namelist.size(); ++i)
@@ -78,7 +78,7 @@ chownRecursive(const string& path, uid_t uid, gid_t gid)
{
if(chown(path.c_str(), uid, gid) != 0)
{
- throw "can't change permissions on `" + name + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("can't change permissions on `" + name + "':\n" + IceUtilInternal::lastErrorToString());
}
}
else if(name != "..")
@@ -88,7 +88,7 @@ chownRecursive(const string& path, uid_t uid, gid_t gid)
IceUtilInternal::structstat buf;
if(IceUtilInternal::stat(name, &buf) == -1)
{
- throw "cannot stat `" + name + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot stat `" + name + "':\n" + IceUtilInternal::lastErrorToString());
}
if(S_ISDIR(buf.st_mode))
@@ -99,7 +99,7 @@ chownRecursive(const string& path, uid_t uid, gid_t gid)
{
if(chown(name.c_str(), uid, gid) != 0)
{
- throw "can't change permissions on `" + name + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("can't change permissions on `" + name + "':\n" + IceUtilInternal::lastErrorToString());
}
}
}
@@ -1353,19 +1353,9 @@ ServerI::checkUpdate(const InternalServerDescriptorPtr& desc, bool noRestart, co
{
checkAndUpdateUser(desc, false); // false = don't update the user, just check.
}
- catch(const Ice::Exception& ex)
- {
- ostringstream os;
- os << ex;
- throw DeploymentException(os.str());
- }
- catch(const string& msg)
+ catch(const exception& ex)
{
- throw DeploymentException(msg);
- }
- catch(const char* msg)
- {
- throw DeploymentException(msg);
+ throw DeploymentException(ex.what());
}
return StopCommand::isStopped(_state);
@@ -1477,10 +1467,10 @@ ServerI::finishPatch()
{
chownRecursive(_serverDir + "/distrib", _uid, _gid);
}
- catch(const string& msg)
+ catch(const exception& ex)
{
Ice::Warning out(_node->getTraceLevels()->logger);
- out << msg;
+ out << ex.what();
}
}
#endif
@@ -1555,9 +1545,7 @@ ServerI::checkDestroyed() const
{
if(_state == Destroyed)
{
- Ice::ObjectNotExistException ex(__FILE__, __LINE__);
- ex.id = _this->ice_getIdentity();
- throw ex;
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__, _this->ice_getIdentity(), "", "");
}
}
@@ -1647,7 +1635,7 @@ ServerI::activate()
if(_activation == Disabled)
{
- throw string("The server is disabled.");
+ throw runtime_error("The server is disabled.");
}
//
@@ -1749,19 +1737,17 @@ ServerI::activate()
}
return;
}
- catch(const std::string& ex)
- {
- failure = ex;
- }
catch(const Ice::Exception& ex)
{
Ice::Warning out(_node->getTraceLevels()->logger);
out << "activation failed for server `" << _id << "':\n";
out << ex;
- ostringstream os;
- os << ex;
- failure = os.str();
+ failure = ex.what();
+ }
+ catch(const std::exception& ex)
+ {
+ failure = ex.what();
}
{
@@ -1890,12 +1876,12 @@ ServerI::destroy()
{
IcePatch2Internal::removeRecursive(_serverDir);
}
- catch(const string& msg)
+ catch(const exception& ex)
{
if(!_destroy->loadFailure())
{
Ice::Warning out(_node->getTraceLevels()->logger);
- out << "removing server directory `" << _serverDir << "' failed:\n" << msg;
+ out << "removing server directory `" << _serverDir << "' failed:\n" << ex.what();
}
}
}
@@ -2050,7 +2036,7 @@ ServerI::update()
{
IcePatch2Internal::removeRecursive(_serverDir);
}
- catch(const string&)
+ catch(const exception&)
{
}
}
@@ -2059,19 +2045,9 @@ ServerI::update()
{
updateImpl(_load->getInternalServerDescriptor());
}
- catch(const Ice::Exception& ex)
- {
- ostringstream os;
- os << ex;
- throw DeploymentException(os.str());
- }
- catch(const string& msg)
+ catch(const exception& ex)
{
- throw DeploymentException(msg);
- }
- catch(const char* msg)
- {
- throw DeploymentException(msg);
+ throw DeploymentException(ex.what());
}
if(oldDescriptor)
@@ -2116,15 +2092,10 @@ ServerI::update()
Ice::Warning out(_node->getTraceLevels()->logger);
out << "update failed:\n" << ex.reason << "\nand couldn't rollback old descriptor:\n" << e;
}
- catch(const string& msg)
- {
- Ice::Warning out(_node->getTraceLevels()->logger);
- out << "update failed:\n" << ex.reason << "\nand couldn't rollback old descriptor:\n" << msg;
- }
- catch(const char* msg)
+ catch(const exception& e)
{
Ice::Warning out(_node->getTraceLevels()->logger);
- out << "update failed:\n" << ex.reason << "\nand couldn't rollback old descriptor:\n" << msg;
+ out << "update failed:\n" << ex.reason << "\nand couldn't rollback old descriptor:\n" << e.what();
}
}
else if(!_destroy)
@@ -2327,7 +2298,7 @@ ServerI::updateImpl(const InternalServerDescriptorPtr& descriptor)
ofstream configfile(IceUtilInternal::streamFilename(configFilePath).c_str()); // configFilePath is a UTF-8 string
if(!configfile.good())
{
- throw "couldn't create configuration file: " + configFilePath;
+ throw runtime_error("couldn't create configuration file: " + configFilePath);
}
configfile << "# Configuration file (" << IceUtil::Time::now().toDateTime() << ")" << endl << endl;
for(PropertyDescriptorSeq::const_iterator r = p->second.begin(); r != p->second.end(); ++r)
@@ -2359,10 +2330,10 @@ ServerI::updateImpl(const InternalServerDescriptorPtr& descriptor)
{
IcePatch2Internal::remove(_serverDir + "/config/" + *q);
}
- catch(const string& msg)
+ catch(const exception& ex)
{
Ice::Warning out(_node->getTraceLevels()->logger);
- out << "couldn't remove file `" + _serverDir + "/config/" + *q + "':\n" + msg;
+ out << "couldn't remove file `" << _serverDir << "/config/" << *q << "':\n" << ex.what();
}
}
}
@@ -2401,10 +2372,10 @@ ServerI::updateImpl(const InternalServerDescriptorPtr& descriptor)
{
IcePatch2Internal::removeRecursive(_serverDir + "/" + *p);
}
- catch(const string& msg)
+ catch(const exception& ex)
{
Ice::Warning out(_node->getTraceLevels()->logger);
- out << "couldn't remove directory `" + _serverDir + "/" + *p + "':\n" + msg;
+ out << "couldn't remove directory `" << _serverDir << "/" << *p << "':\n" << ex.what();
}
}
}
@@ -2429,7 +2400,7 @@ ServerI::updateImpl(const InternalServerDescriptorPtr& descriptor)
ofstream configfile(IceUtilInternal::streamFilename(file).c_str()); // file is a UTF-8 string
if(!configfile.good())
{
- throw "couldn't create configuration file `" + file + "'";
+ throw runtime_error("couldn't create configuration file `" + file + "'");
}
for(PropertyDescriptorSeq::const_iterator p = (*q)->properties.begin();
@@ -2462,10 +2433,10 @@ ServerI::updateImpl(const InternalServerDescriptorPtr& descriptor)
{
IcePatch2Internal::removeRecursive(_serverDir + "/dbs/" + *p);
}
- catch(const string& msg)
+ catch(const exception& ex)
{
Ice::Warning out(_node->getTraceLevels()->logger);
- out << "couldn't remove directory `" + _serverDir + "/dbs/" + *p + "':\n" + msg;
+ out << "couldn't remove directory `" << _serverDir << "/dbs/" << *p << "':\n" << ex.what();
}
}
}
@@ -2515,16 +2486,14 @@ ServerI::checkRevision(const string& replicaName, const string& uuid, int revisi
if(uuid != descUUID)
{
- DeploymentException ex;
- ex.reason = "server from replica `" + replicaName + "' is from another application (`" + uuid + "')";
- throw ex;
+ throw DeploymentException("server from replica `" + replicaName + "' is from another application (`" + uuid +
+ "')");
}
else if(revision != descRevision)
{
ostringstream os;
- os << "server from replica `" + replicaName + "' has a different version:\n";
- os << "current revision: " << descRevision << "\n";
- os << "replica revision: " << revision;
+ os << "server from replica `" << replicaName << "' has a different version:\n"
+ << "current revision: " << descRevision << "\nreplica revision: " << revision;
throw DeploymentException(os.str());
}
}
@@ -2594,13 +2563,13 @@ ServerI::checkAndUpdateUser(const InternalServerDescriptorPtr& desc, bool /*upda
}
catch(const UserAccountNotFoundException&)
{
- throw "couldn't find user account for user `" + user + "'";
+ throw runtime_error("couldn't find user account for user `" + user + "'");
}
catch(const Ice::LocalException& ex)
{
ostringstream os;
os << "unexpected exception while trying to find user account for user `" << user << "':\n" << ex;
- throw os.str();
+ throw runtime_error(os.str());
}
}
@@ -2623,13 +2592,11 @@ ServerI::checkAndUpdateUser(const InternalServerDescriptorPtr& desc, bool /*upda
}
if(!success)
{
- Ice::SyscallException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSystemErrno();
- throw ex;
+ throw Ice::SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno());
}
if(user != string(&buf[0]))
{
- throw "couldn't load server under user account `" + user + "': feature not supported on Windows";
+ throw runtime_error("couldn't load server under user account `" + user + "': feature not supported on Windows");
}
}
#else
@@ -2646,13 +2613,11 @@ ServerI::checkAndUpdateUser(const InternalServerDescriptorPtr& desc, bool /*upda
}
if(err != 0)
{
- Ice::SyscallException ex(__FILE__, __LINE__);
- ex.error = err;
- throw ex;
+ throw Ice::SyscallException(__FILE__, __LINE__, err);
}
else if(pw == 0)
{
- throw "unknown user account `" + user + "'";
+ throw runtime_error("unknown user account `" + user + "'");
}
//
@@ -2663,13 +2628,13 @@ ServerI::checkAndUpdateUser(const InternalServerDescriptorPtr& desc, bool /*upda
//
if(uid != 0 && pw->pw_uid != uid)
{
- throw "node has insufficient privileges to load server under user account `" + user + "'";
+ throw runtime_error("node has insufficient privileges to load server under user account `" + user + "'");
}
if(pw->pw_uid == 0 &&
_node->getCommunicator()->getProperties()->getPropertyAsInt("IceGrid.Node.AllowRunningServersAsRoot") <= 0)
{
- throw "running server as `root' is not allowed";
+ throw runtime_error("running server as `root' is not allowed");
}
if(update)
diff --git a/cpp/src/IceGrid/SessionI.cpp b/cpp/src/IceGrid/SessionI.cpp
index 52f880936e1..9f9b40bec04 100644
--- a/cpp/src/IceGrid/SessionI.cpp
+++ b/cpp/src/IceGrid/SessionI.cpp
@@ -89,9 +89,7 @@ BaseSessionI::keepAlive(const Ice::Current& current)
Lock sync(*this);
if(_destroyed)
{
- Ice::ObjectNotExistException ex(__FILE__, __LINE__);
- ex.id = current.id;
- throw ex;
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__, current.id, "", "");
}
_timestamp = IceUtil::Time::now(IceUtil::Time::Monotonic);
@@ -340,9 +338,7 @@ ClientSessionFactory::createGlacier2Session(const string& sessionId, const Glaci
Ice::Warning out(_database->getTraceLevels()->logger);
out << "Failed to callback Glacier2 session control object:\n" << e;
- Glacier2::CannotCreateSessionException ex;
- ex.reason = "internal server error";
- throw ex;
+ throw Glacier2::CannotCreateSessionException("internal server error");
}
}
@@ -395,9 +391,7 @@ ClientSSLSessionManagerI::create(const Glacier2::SSLInfo& info,
Ice::Error out(_factory->getTraceLevels()->logger);
out << "SSL session manager couldn't decode SSL certificates:\n" << e;
- Glacier2::CannotCreateSessionException ex;
- ex.reason = "internal server error";
- throw ex;
+ throw Glacier2::CannotCreateSessionException("internal server error");
}
}
diff --git a/cpp/src/IceGrid/Topics.cpp b/cpp/src/IceGrid/Topics.cpp
index 568e753f16d..1ec50249a0c 100644
--- a/cpp/src/IceGrid/Topics.cpp
+++ b/cpp/src/IceGrid/Topics.cpp
@@ -724,6 +724,12 @@ ApplicationObserverTopic::applicationUpdated(Ice::Long dbSerial, const Applicati
out << "unexpected exception while instantiating application `" << info.descriptor.name << "':\n" << ex.reason;
assert(false);
}
+ catch(const std::exception& ex)
+ {
+ Ice::Error out(_logger);
+ out << "unexpected exception while instantiating application `" << info.descriptor.name << "':\n" << ex.what();
+ assert(false);
+ }
catch(const std::string& msg)
{
Ice::Error out(_logger);
diff --git a/cpp/src/IcePatch2/Calc.cpp b/cpp/src/IcePatch2/Calc.cpp
index 167d59d797e..47df39335e5 100644
--- a/cpp/src/IcePatch2/Calc.cpp
+++ b/cpp/src/IcePatch2/Calc.cpp
@@ -203,7 +203,7 @@ main(int argc, char* argv[])
string cwd;
if(IceUtilInternal::getcwd(cwd) != 0)
{
- throw "cannot get the current directory:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot get the current directory:\n" + IceUtilInternal::lastErrorToString());
}
if(!IceUtilInternal::isAbsolutePath(absDataDir))
@@ -230,7 +230,7 @@ main(int argc, char* argv[])
{
if(p->compare(0, absDataDirWithSlash.size(), absDataDirWithSlash) != 0)
{
- throw "`" + *p + "' is not a path in `" + dataDir + "'";
+ throw runtime_error("`" + *p + "' is not a path in `" + dataDir + "'");
}
p->erase(0, absDataDirWithSlash.size());
@@ -290,31 +290,29 @@ main(int argc, char* argv[])
{
LargeFileInfoSeq newInfoSeq = infoSeq;
sort(newInfoSeq.begin(), newInfoSeq.end(), IFileInfoPathLess());
-
- string ex;
+ string reason;
LargeFileInfoSeq::iterator p = newInfoSeq.begin();
while((p = adjacent_find(p, newInfoSeq.end(), IFileInfoPathEqual())) != newInfoSeq.end())
{
do
{
- ex += '\n' + dataDir + '/' + p->path;
+ reason += '\n' + dataDir + '/' + p->path;
++p;
}
while(p < newInfoSeq.end() && IFileInfoPathEqual()(*(p - 1), *p));
}
- if(!ex.empty())
+ if(!reason.empty())
{
- ex = "duplicate files:" + ex;
- throw ex;
+ throw runtime_error("duplicate files:" + reason);
}
}
saveFileInfoSeq(absDataDir, infoSeq);
}
- catch(const string& ex)
+ catch(const exception& ex)
{
- consoleErr << appName << ": " << ex << endl;
+ consoleErr << appName << ": " << ex.what() << endl;
return EXIT_FAILURE;
}
catch(const char* ex)
diff --git a/cpp/src/IcePatch2/Client.cpp b/cpp/src/IcePatch2/Client.cpp
index 4f5f7503e08..cf4392736eb 100644
--- a/cpp/src/IcePatch2/Client.cpp
+++ b/cpp/src/IcePatch2/Client.cpp
@@ -333,9 +333,9 @@ Client::run(int argc, char* argv[])
patcher->finish();
}
}
- catch(const string& ex)
+ catch(const exception& ex)
{
- consoleErr << argv[0] << ": " << ex << endl;
+ consoleErr << argv[0] << ": " << ex.what() << endl;
return EXIT_FAILURE;
}
diff --git a/cpp/src/IcePatch2/Server.cpp b/cpp/src/IcePatch2/Server.cpp
index a3e29e83555..224137c419b 100644
--- a/cpp/src/IcePatch2/Server.cpp
+++ b/cpp/src/IcePatch2/Server.cpp
@@ -107,7 +107,7 @@ IcePatch2::PatcherService::start(int argc, char* argv[], int& status)
string cwd;
if(IceUtilInternal::getcwd(cwd) != 0)
{
- throw "cannot get the current directory:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot get the current directory:\n" + IceUtilInternal::lastErrorToString());
}
dataDir = cwd + '/' + dataDir;
@@ -115,14 +115,9 @@ IcePatch2::PatcherService::start(int argc, char* argv[], int& status)
loadFileInfoSeq(dataDir, infoSeq);
}
- catch(const string& ex)
+ catch(const exception& ex)
{
- error(ex);
- return false;
- }
- catch(const char* ex)
- {
- error(ex);
+ error(ex.what());
return false;
}
diff --git a/cpp/src/IcePatch2Lib/ClientUtil.cpp b/cpp/src/IcePatch2Lib/ClientUtil.cpp
index 9f7be8b649f..a2f179a18ac 100644
--- a/cpp/src/IcePatch2Lib/ClientUtil.cpp
+++ b/cpp/src/IcePatch2Lib/ClientUtil.cpp
@@ -119,7 +119,7 @@ Decompressor::add(const LargeFileInfo& info)
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
if(!_exception.empty())
{
- throw _exception;
+ throw runtime_error(_exception);
}
_files.push_back(info);
notify();
@@ -131,7 +131,7 @@ Decompressor::exception() const
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
if(!_exception.empty())
{
- throw _exception;
+ throw runtime_error(_exception);
}
}
@@ -144,7 +144,7 @@ Decompressor::log(FILE* fp)
{
if(fputc('+', fp) == EOF || !writeFileInfo(fp, *p))
{
- throw "error writing log file:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("error writing log file:\n" + IceUtilInternal::lastErrorToString());
}
}
@@ -188,11 +188,11 @@ Decompressor::run()
setFileFlags(_dataDir + '/' + info.path, info);
remove(_dataDir + '/' + info.path + ".bz2");
}
- catch(const string& ex)
+ catch(const std::exception& ex)
{
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
_destroy = true;
- _exception = ex;
+ _exception = ex.what();
return;
}
}
@@ -211,13 +211,13 @@ PatcherI::PatcherI(const CommunicatorPtr& communicator, const PatcherFeedbackPtr
string clientProxy = communicator->getProperties()->getProperty(clientProxyProperty);
if(clientProxy.empty())
{
- throw "property `IcePatch2Client.Proxy' is not set";
+ throw runtime_error("property `IcePatch2Client.Proxy' is not set");
}
FileServerPrx server = FileServerPrx::checkedCast(communicator->stringToProxy(clientProxy));
if(!server)
{
- throw "proxy `" + clientProxy + "' is not a file server.";
+ throw runtime_error("proxy `" + clientProxy + "' is not a file server.");
}
init(server);
@@ -293,9 +293,9 @@ PatcherI::prepare()
{
loadFileInfoSeq(_dataDir, _localFiles);
}
- catch(const string& ex)
+ catch(const exception& ex)
{
- thorough = _feedback->noFileSummary(ex);
+ thorough = _feedback->noFileSummary(ex.what());
if(!thorough)
{
return false;
@@ -337,7 +337,7 @@ PatcherI::prepare()
ByteSeqSeq checksumSeq = _serverCompress->getChecksumSeq();
if(checksumSeq.size() != 256)
{
- throw string("server returned illegal value");
+ throw runtime_error("server returned illegal value");
}
while(true)
@@ -471,7 +471,7 @@ PatcherI::prepare()
_log = IceUtilInternal::fopen(pathLog, "w");
if(!_log)
{
- throw "cannot open `" + pathLog + "' for writing:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot open `" + pathLog + "' for writing:\n" + IceUtilInternal::lastErrorToString());
}
return true;
@@ -598,7 +598,7 @@ PatcherI::init(const FileServerPrx& server)
{
if(_dataDir.empty())
{
- throw string("no data directory specified");
+ throw runtime_error("no data directory specified");
}
Ice::CommunicatorPtr communicator = server->ice_getCommunicator();
@@ -632,7 +632,7 @@ PatcherI::init(const FileServerPrx& server)
string cwd;
if(IceUtilInternal::getcwd(cwd) != 0)
{
- throw "cannot get the current directory:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot get the current directory:\n" + IceUtilInternal::lastErrorToString());
}
const_cast<string&>(_dataDir) = simplify(cwd + '/' + _dataDir);
}
@@ -656,7 +656,7 @@ PatcherI::removeFiles(const LargeFileInfoSeq& files)
remove(_dataDir + '/' + p->path);
if(fputc('-', _log) == EOF || ! writeFileInfo(_log, *p))
{
- throw "error writing log file:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("error writing log file:\n" + IceUtilInternal::lastErrorToString());
}
}
catch(...)
@@ -753,7 +753,7 @@ PatcherI::updateFilesInternal(const LargeFileInfoSeq& files, const DecompressorP
createDirectoryRecursive(_dataDir + '/' + p->path);
if(fputc('+', _log) == EOF || !writeFileInfo(_log, *p))
{
- throw "error writing log file:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("error writing log file:\n" + IceUtilInternal::lastErrorToString());
}
}
else // Regular file.
@@ -769,7 +769,7 @@ PatcherI::updateFilesInternal(const LargeFileInfoSeq& files, const DecompressorP
FILE* fp = IceUtilInternal::fopen(path, "wb");
if(fp == 0)
{
- throw "cannot open `" + path +"' for writing:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot open `" + path +"' for writing:\n" + IceUtilInternal::lastErrorToString());
}
fclose(fp);
}
@@ -794,7 +794,7 @@ PatcherI::updateFilesInternal(const LargeFileInfoSeq& files, const DecompressorP
FILE* fileBZ2 = IceUtilInternal::fopen(pathBZ2, "wb");
if(fileBZ2 == 0)
{
- throw "cannot open `" + pathBZ2 + "' for writing:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot open `" + pathBZ2 + "' for writing:\n" + IceUtilInternal::lastErrorToString());
}
try
@@ -848,17 +848,17 @@ PatcherI::updateFilesInternal(const LargeFileInfoSeq& files, const DecompressorP
}
catch(const FileAccessException& ex)
{
- throw "error from IcePatch2 server for `" + p->path + "': " + ex.reason;
+ throw runtime_error("error from IcePatch2 server for `" + p->path + "': " + ex.reason);
}
if(bytes.empty())
{
- throw "size mismatch for `" + p->path + "'";
+ throw runtime_error("size mismatch for `" + p->path + "'");
}
if(fwrite(reinterpret_cast<char*>(&bytes[0]), bytes.size(), 1, fileBZ2) != 1)
{
- throw ": cannot write `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error(": cannot write `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString());
}
// 'bytes' is always returned with size '_chunkSize'. When a file is smaller than '_chunkSize'
diff --git a/cpp/src/IcePatch2Lib/Util.cpp b/cpp/src/IcePatch2Lib/Util.cpp
index 4fb9f32850d..447d4d44e36 100644
--- a/cpp/src/IcePatch2Lib/Util.cpp
+++ b/cpp/src/IcePatch2Lib/Util.cpp
@@ -118,7 +118,7 @@ IcePatch2Internal::readFileInfo(FILE* fp, LargeFileInfo& info)
}
catch(const IceUtil::IllegalArgumentException& ex)
{
- throw ex.reason();
+ throw invalid_argument(ex.reason());
}
getline(is, s, '\t');
@@ -373,9 +373,9 @@ IcePatch2Internal::rename(const string& fromPa, const string& toPa)
const string toPath = simplify(toPa);
IceUtilInternal::remove(toPath); // We ignore errors, as the file we are renaming to might not exist.
- if(IceUtilInternal::rename(fromPath ,toPath) == -1)
+ if(IceUtilInternal::rename(fromPath, toPath) == -1)
{
- throw "cannot rename `" + fromPath + "' to `" + toPath + "': " + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot rename `" + fromPath + "' to `" + toPath + "': " + IceUtilInternal::lastErrorToString());
}
}
@@ -387,7 +387,7 @@ IcePatch2Internal::remove(const string& pa)
IceUtilInternal::structstat buf;
if(IceUtilInternal::stat(path, &buf) == -1)
{
- throw "cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
if(S_ISDIR(buf.st_mode))
@@ -398,14 +398,14 @@ IcePatch2Internal::remove(const string& pa)
{
assert(false);
}
- throw "cannot remove directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot remove directory `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
}
else
{
if(IceUtilInternal::remove(path) == -1)
{
- throw "cannot remove file `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot remove file `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
}
}
@@ -418,7 +418,7 @@ IcePatch2Internal::removeRecursive(const string& pa)
IceUtilInternal::structstat buf;
if(IceUtilInternal::stat(path, &buf) == -1)
{
- throw "cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
if(S_ISDIR(buf.st_mode))
@@ -433,7 +433,7 @@ IcePatch2Internal::removeRecursive(const string& pa)
{
if(IceUtilInternal::rmdir(path) == -1)
{
- throw "cannot remove directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot remove directory `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
}
}
@@ -441,7 +441,7 @@ IcePatch2Internal::removeRecursive(const string& pa)
{
if(IceUtilInternal::remove(path) == -1)
{
- throw "cannot remove file `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot remove file `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
}
}
@@ -464,7 +464,7 @@ IcePatch2Internal::readDirectory(const string& pa)
intptr_t h = _wfindfirst(fs.c_str(), &data);
if(h == -1)
{
- throw "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
while(true)
@@ -483,10 +483,9 @@ IcePatch2Internal::readDirectory(const string& pa)
{
break;
}
-
- string ex = "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ string reason = "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
_findclose(h);
- throw ex;
+ throw runtime_error(reason);
}
}
@@ -502,7 +501,7 @@ IcePatch2Internal::readDirectory(const string& pa)
if(n < 0)
{
- throw "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
StringSeq result;
@@ -536,7 +535,7 @@ IcePatch2Internal::createDirectory(const string& pa)
{
if(errno != EEXIST)
{
- throw "cannot create directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot create directory `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
}
}
@@ -567,7 +566,7 @@ IcePatch2Internal::createDirectoryRecursive(const string& pa)
{
if(errno != EEXIST)
{
- throw "cannot create directory `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot create directory `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
}
}
@@ -581,45 +580,45 @@ IcePatch2Internal::compressBytesToFile(const string& pa, const ByteSeq& bytes, I
FILE* stdioFile = IceUtilInternal::fopen(path, "wb");
if(!stdioFile)
{
- throw "cannot open `" + path + "' for writing:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot open `" + path + "' for writing:\n" + IceUtilInternal::lastErrorToString());
}
int bzError;
BZFILE* bzFile = BZ2_bzWriteOpen(&bzError, stdioFile, 5, 0, 0);
if(bzError != BZ_OK)
{
- string ex = "BZ2_bzWriteOpen failed";
+ string reason = "BZ2_bzWriteOpen failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + IceUtilInternal::lastErrorToString();
+ reason += ": " + IceUtilInternal::lastErrorToString();
}
fclose(stdioFile);
- throw ex;
+ throw runtime_error(reason);
}
BZ2_bzWrite(&bzError, bzFile, const_cast<Byte*>(&bytes[pos]), static_cast<int>(bytes.size() - pos));
if(bzError != BZ_OK)
{
- string ex = "BZ2_bzWrite failed";
+ string reason = "BZ2_bzWrite failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + IceUtilInternal::lastErrorToString();
+ reason += ": " + IceUtilInternal::lastErrorToString();
}
BZ2_bzWriteClose(&bzError, bzFile, 0, 0, 0);
fclose(stdioFile);
- throw ex;
+ throw runtime_error(reason);
}
BZ2_bzWriteClose(&bzError, bzFile, 0, 0, 0);
if(bzError != BZ_OK)
{
- string ex = "BZ2_bzWriteClose failed";
+ string reason = "BZ2_bzWriteClose failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + IceUtilInternal::lastErrorToString();
+ reason += ": " + IceUtilInternal::lastErrorToString();
}
fclose(stdioFile);
- throw ex;
+ throw runtime_error(reason);
}
fclose(stdioFile);
@@ -641,24 +640,24 @@ IcePatch2Internal::decompressFile(const string& pa)
fp = IceUtilInternal::fopen(path, "wb");
if(!fp)
{
- throw "cannot open `" + path + "' for writing:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot open `" + path + "' for writing:\n" + IceUtilInternal::lastErrorToString());
}
stdioFileBZ2 = IceUtilInternal::fopen(pathBZ2, "rb");
if(!stdioFileBZ2)
{
- throw "cannot open `" + pathBZ2 + "' for reading:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot open `" + pathBZ2 + "' for reading:\n" + IceUtilInternal::lastErrorToString());
}
bzFile = BZ2_bzReadOpen(&bzError, stdioFileBZ2, 0, 0, 0, 0);
if(bzError != BZ_OK)
{
- string ex = "BZ2_bzReadOpen failed";
+ string reason = "BZ2_bzReadOpen failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + IceUtilInternal::lastErrorToString();
+ reason += ": " + IceUtilInternal::lastErrorToString();
}
- throw ex;
+ throw runtime_error(reason);
}
const Int numBZ2 = 64 * 1024;
@@ -669,12 +668,12 @@ IcePatch2Internal::decompressFile(const string& pa)
int sz = BZ2_bzRead(&bzError, bzFile, bytesBZ2, numBZ2);
if(bzError != BZ_OK && bzError != BZ_STREAM_END)
{
- string ex = "BZ2_bzRead failed";
+ string reason = "BZ2_bzRead failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + IceUtilInternal::lastErrorToString();
+ reason += ": " + IceUtilInternal::lastErrorToString();
}
- throw ex;
+ throw runtime_error(reason);
}
if(sz > 0)
@@ -682,12 +681,12 @@ IcePatch2Internal::decompressFile(const string& pa)
long pos = ftell(stdioFileBZ2);
if(pos == -1)
{
- throw "cannot get read position for `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot get read position for `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString());
}
if(fwrite(bytesBZ2, sz, 1, fp) != 1)
{
- throw "cannot write to `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot write to `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
}
}
@@ -696,12 +695,12 @@ IcePatch2Internal::decompressFile(const string& pa)
bzFile = 0;
if(bzError != BZ_OK)
{
- string ex = "BZ2_bzReadClose failed";
+ string reason = "BZ2_bzReadClose failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + IceUtilInternal::lastErrorToString();
+ reason += ": " + IceUtilInternal::lastErrorToString();
}
- throw ex;
+ throw runtime_error(reason);
}
}
catch(...)
@@ -733,7 +732,7 @@ IcePatch2Internal::setFileFlags(const string& pa, const LargeFileInfo& info)
IceUtilInternal::structstat buf;
if(IceUtilInternal::stat(path, &buf) == -1)
{
- throw "cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
chmod(path.c_str(), info.executable ? buf.st_mode | S_IXUSR : buf.st_mode & ~S_IXUSR);
}
@@ -787,7 +786,7 @@ getFileInfoSeqInternal(const string& basePath, const string& relPath, int compre
}
else
{
- throw "cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
}
else if(buf.st_size == 0)
@@ -807,7 +806,7 @@ getFileInfoSeqInternal(const string& basePath, const string& relPath, int compre
IceUtilInternal::structstat buf;
if(IceUtilInternal::stat(path, &buf) == -1)
{
- throw "cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
if(S_ISDIR(buf.st_mode))
@@ -903,7 +902,7 @@ getFileInfoSeqInternal(const string& basePath, const string& relPath, int compre
int fd = IceUtilInternal::open(path.c_str(), O_BINARY|O_RDONLY);
if(fd == -1)
{
- throw "cannot open `" + path + "' for reading:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot open `" + path + "' for reading:\n" + IceUtilInternal::lastErrorToString());
}
const string pathBZ2Temp = path + ".bz2temp";
@@ -916,20 +915,20 @@ getFileInfoSeqInternal(const string& basePath, const string& relPath, int compre
if(!stdioFile)
{
IceUtilInternal::close(fd);
- throw "cannot open `" + pathBZ2Temp + "' for writing:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot open `" + pathBZ2Temp + "' for writing:\n" + IceUtilInternal::lastErrorToString());
}
bzFile = BZ2_bzWriteOpen(&bzError, stdioFile, 5, 0, 0);
if(bzError != BZ_OK)
{
- string ex = "BZ2_bzWriteOpen failed";
+ string reason = "BZ2_bzWriteOpen failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + IceUtilInternal::lastErrorToString();
+ reason += ": " + IceUtilInternal::lastErrorToString();
}
fclose(stdioFile);
IceUtilInternal::close(fd);
- throw ex;
+ throw runtime_error(reason);
}
}
@@ -951,7 +950,7 @@ getFileInfoSeqInternal(const string& basePath, const string& relPath, int compre
}
IceUtilInternal::close(fd);
- throw "cannot read from `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot read from `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
bytesLeft -= static_cast<unsigned int>(bytes.size());
if(doCompress)
@@ -959,15 +958,15 @@ getFileInfoSeqInternal(const string& basePath, const string& relPath, int compre
BZ2_bzWrite(&bzError, bzFile, const_cast<Byte*>(&bytes[0]), static_cast<int>(bytes.size()));
if(bzError != BZ_OK)
{
- string ex = "BZ2_bzWrite failed";
+ string reason = "BZ2_bzWrite failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + IceUtilInternal::lastErrorToString();
+ reason += ": " + IceUtilInternal::lastErrorToString();
}
BZ2_bzWriteClose(&bzError, bzFile, 0, 0, 0);
fclose(stdioFile);
IceUtilInternal::close(fd);
- throw ex;
+ throw runtime_error(reason);
}
}
@@ -981,13 +980,13 @@ getFileInfoSeqInternal(const string& basePath, const string& relPath, int compre
BZ2_bzWriteClose(&bzError, bzFile, 0, 0, 0);
if(bzError != BZ_OK)
{
- string ex = "BZ2_bzWriteClose failed";
+ string reason = "BZ2_bzWriteClose failed";
if(bzError == BZ_IO_ERROR)
{
- ex += string(": ") + IceUtilInternal::lastErrorToString();
+ reason += ": " + IceUtilInternal::lastErrorToString();
}
fclose(stdioFile);
- throw ex;
+ throw runtime_error(reason);
}
fclose(stdioFile);
@@ -996,7 +995,7 @@ getFileInfoSeqInternal(const string& basePath, const string& relPath, int compre
if(IceUtilInternal::stat(pathBZ2, &bufBZ2) == -1)
{
- throw "cannot stat `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot stat `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString());
}
info.size = bufBZ2.st_size;
@@ -1054,7 +1053,7 @@ IcePatch2Internal::saveFileInfoSeq(const string& pa, const LargeFileInfoSeq& inf
FILE* fp = IceUtilInternal::fopen(path, "w");
if(!fp)
{
- throw "cannot open `" + path + "' for writing:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot open `" + path + "' for writing:\n" + IceUtilInternal::lastErrorToString());
}
try
{
@@ -1062,7 +1061,7 @@ IcePatch2Internal::saveFileInfoSeq(const string& pa, const LargeFileInfoSeq& inf
{
if(!writeFileInfo(fp, *p))
{
- throw "error writing `" + path + "':\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("error writing `" + path + "':\n" + IceUtilInternal::lastErrorToString());
}
}
}
@@ -1096,7 +1095,7 @@ IcePatch2Internal::loadFileInfoSeq(const string& pa, LargeFileInfoSeq& infoSeq)
FILE* fp = IceUtilInternal::fopen(path, "r");
if(!fp)
{
- throw "cannot open `" + path + "' for reading:\n" + IceUtilInternal::lastErrorToString();
+ throw runtime_error("cannot open `" + path + "' for reading:\n" + IceUtilInternal::lastErrorToString());
}
while(true)
diff --git a/cpp/src/IceSSL/AcceptorI.cpp b/cpp/src/IceSSL/AcceptorI.cpp
index 68efd03c04f..bea1ceaf915 100644
--- a/cpp/src/IceSSL/AcceptorI.cpp
+++ b/cpp/src/IceSSL/AcceptorI.cpp
@@ -72,9 +72,7 @@ IceSSL::AcceptorI::accept()
//
if(!_instance->initialized())
{
- PluginInitializationException ex(__FILE__, __LINE__);
- ex.reason = "IceSSL: plug-in is not initialized";
- throw ex;
+ throw PluginInitializationException(__FILE__, __LINE__, "IceSSL: plug-in is not initialized");
}
return _instance->engine()->createTransceiver(_instance, _delegate->accept(), _adapterName, true);
diff --git a/cpp/src/IceSSL/ConnectorI.cpp b/cpp/src/IceSSL/ConnectorI.cpp
index cce51d27217..d464cc16715 100644
--- a/cpp/src/IceSSL/ConnectorI.cpp
+++ b/cpp/src/IceSSL/ConnectorI.cpp
@@ -31,9 +31,7 @@ IceSSL::ConnectorI::connect()
//
if(!_instance->initialized())
{
- PluginInitializationException ex(__FILE__, __LINE__);
- ex.reason = "IceSSL: plug-in is not initialized";
- throw ex;
+ throw PluginInitializationException(__FILE__, __LINE__, "IceSSL: plug-in is not initialized");
}
return _instance->engine()->createTransceiver(_instance, _delegate->connect(), _host, false);
diff --git a/cpp/src/IceSSL/OpenSSLTransceiverI.cpp b/cpp/src/IceSSL/OpenSSLTransceiverI.cpp
index 0c0d60fc74f..a8a4b9e1079 100644
--- a/cpp/src/IceSSL/OpenSSLTransceiverI.cpp
+++ b/cpp/src/IceSSL/OpenSSLTransceiverI.cpp
@@ -127,9 +127,7 @@ OpenSSL::TransceiverI::initialize(IceInternal::Buffer& readBuffer, IceInternal::
if(!bio)
{
- SecurityException ex(__FILE__, __LINE__);
- ex.reason = "openssl failure";
- throw ex;
+ throw SecurityException(__FILE__, __LINE__, "openssl failure");
}
_ssl = SSL_new(_engine->context());
@@ -140,9 +138,7 @@ OpenSSL::TransceiverI::initialize(IceInternal::Buffer& readBuffer, IceInternal::
BIO_free(_iocpBio);
_iocpBio = 0;
#endif
- SecurityException ex(__FILE__, __LINE__);
- ex.reason = "openssl failure";
- throw ex;
+ throw SecurityException(__FILE__, __LINE__, "openssl failure");
}
SSL_set_bio(_ssl, bio, bio);
@@ -239,9 +235,7 @@ OpenSSL::TransceiverI::initialize(IceInternal::Buffer& readBuffer, IceInternal::
}
case SSL_ERROR_ZERO_RETURN:
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
case SSL_ERROR_WANT_READ:
{
@@ -287,23 +281,17 @@ OpenSSL::TransceiverI::initialize(IceInternal::Buffer& readBuffer, IceInternal::
if(IceInternal::connectionLost() || IceInternal::getSocketErrno() == 0)
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
#endif
- SocketException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
case SSL_ERROR_SSL:
{
ostringstream ostr;
ostr << "SSL error occurred for new " << (_incoming ? "incoming" : "outgoing")
<< " connection:\nremote address = " << _delegate->toString() << "\n" << _engine->sslErrors();
- ProtocolException ex(__FILE__, __LINE__);
- ex.reason = ostr.str();
- throw ex;
+ throw ProtocolException(__FILE__, __LINE__, ostr.str());
}
}
}
@@ -325,14 +313,12 @@ OpenSSL::TransceiverI::initialize(IceInternal::Buffer& readBuffer, IceInternal::
{
ostringstream ostr;
ostr << "IceSSL: certificate verification failed:\n" << X509_verify_cert_error_string(result);
- string msg = ostr.str();
+ const string msg = ostr.str();
if(_engine->securityTraceLevel() >= 1)
{
_instance->logger()->trace(_instance->traceCategory(), msg);
}
- SecurityException ex(__FILE__, __LINE__);
- ex.reason = msg;
- throw ex;
+ throw SecurityException(__FILE__, __LINE__, msg);
}
}
else
@@ -473,9 +459,7 @@ OpenSSL::TransceiverI::write(IceInternal::Buffer& buf)
break;
case SSL_ERROR_ZERO_RETURN:
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
case SSL_ERROR_WANT_READ:
{
@@ -515,22 +499,17 @@ OpenSSL::TransceiverI::write(IceInternal::Buffer& buf)
#endif
if(IceInternal::connectionLost() || IceInternal::getSocketErrno() == 0)
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
}
case SSL_ERROR_SSL:
{
- ProtocolException ex(__FILE__, __LINE__);
- ex.reason = "SSL protocol error during write:\n" + _engine->sslErrors();
- throw ex;
+ throw ProtocolException(__FILE__, __LINE__,
+ "SSL protocol error during write:\n" + _engine->sslErrors());
}
}
}
@@ -595,9 +574,7 @@ OpenSSL::TransceiverI::read(IceInternal::Buffer& buf)
}
case SSL_ERROR_ZERO_RETURN:
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, 0);
}
case SSL_ERROR_WANT_READ:
{
@@ -636,22 +613,17 @@ OpenSSL::TransceiverI::read(IceInternal::Buffer& buf)
#endif
if(IceInternal::connectionLost() || IceInternal::getSocketErrno() == 0)
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
}
case SSL_ERROR_SSL:
{
- ProtocolException ex(__FILE__, __LINE__);
- ex.reason = "SSL protocol error during read:\n" + _engine->sslErrors();
- throw ex;
+ throw ProtocolException(__FILE__, __LINE__,
+ "SSL protocol error during read:\n" + _engine->sslErrors());
}
}
}
@@ -758,9 +730,7 @@ OpenSSL::TransceiverI::finishRead(IceInternal::Buffer& buffer)
int n = BIO_write(_iocpBio, _readBuffer.b.begin(), static_cast<int>(_readBuffer.b.size()));
if(n < 0) // Expected if the transceiver was closed.
{
- SecurityException ex(__FILE__, __LINE__);
- ex.reason = "SSL bio write failed";
- throw ex;
+ throw SecurityException(__FILE__, __LINE__, "SSL bio write failed");
}
assert(n == static_cast<int>(_readBuffer.b.size()));
@@ -778,9 +748,7 @@ OpenSSL::TransceiverI::finishRead(IceInternal::Buffer& buffer)
}
case SSL_ERROR_ZERO_RETURN:
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, 0);
}
case SSL_ERROR_WANT_READ:
{
@@ -790,22 +758,17 @@ OpenSSL::TransceiverI::finishRead(IceInternal::Buffer& buffer)
{
if(IceInternal::connectionLost() || IceInternal::getSocketErrno() == 0)
{
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw ConnectionLostException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = IceInternal::getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, IceInternal::getSocketErrno());
}
}
case SSL_ERROR_SSL:
{
- ProtocolException ex(__FILE__, __LINE__);
- ex.reason = "SSL protocol error during read:\n" + _engine->sslErrors();
- throw ex;
+ throw ProtocolException(__FILE__, __LINE__,
+ "SSL protocol error during read:\n" + _engine->sslErrors());
}
}
}
diff --git a/cpp/src/IceSSL/SChannelTransceiverI.cpp b/cpp/src/IceSSL/SChannelTransceiverI.cpp
index 943df427c57..6e7501fe36a 100644
--- a/cpp/src/IceSSL/SChannelTransceiverI.cpp
+++ b/cpp/src/IceSSL/SChannelTransceiverI.cpp
@@ -663,21 +663,20 @@ SChannel::TransceiverI::initialize(IceInternal::Buffer& readBuffer, IceInternal:
}
else if(cert) // Verify the remote certificate
{
- try
+ CERT_CHAIN_PARA chainP;
+ memset(&chainP, 0, sizeof(chainP));
+ chainP.cbSize = sizeof(chainP);
+
+ string trustError;
+ PCCERT_CHAIN_CONTEXT certChain;
+ if(!CertGetCertificateChain(_engine->chainEngine(), cert, 0, 0, &chainP,
+ CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY, 0, &certChain))
+ {
+ CertFreeCertificateContext(cert);
+ trustError = IceUtilInternal::lastErrorToString();
+ }
+ else
{
- CERT_CHAIN_PARA chainP;
- memset(&chainP, 0, sizeof(chainP));
- chainP.cbSize = sizeof(chainP);
-
- PCCERT_CHAIN_CONTEXT certChain;
- if(!CertGetCertificateChain(_engine->chainEngine(), cert, 0, 0, &chainP,
- CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY, 0, &certChain))
- {
- CertFreeCertificateContext(cert);
- throw IceUtilInternal::lastErrorToString();
- }
-
- string trustError;
if(certChain->TrustStatus.dwErrorStatus != CERT_TRUST_NO_ERROR)
{
trustError = trustStatusToString(certChain->TrustStatus.dwErrorStatus);
@@ -699,36 +698,29 @@ SChannel::TransceiverI::initialize(IceInternal::Buffer& readBuffer, IceInternal:
{
CertFreeCertificateChain(certChain);
CertFreeCertificateContext(cert);
- throw SecurityException(__FILE__, __LINE__,
- "IceSSL: error decoding peer certificate chain:\n" +
+ throw SecurityException(__FILE__, __LINE__, "IceSSL: error decoding peer certificate chain:\n" +
IceUtilInternal::lastErrorToString());
}
-
_certs.push_back(SChannel::Certificate::create(cc));
}
CertFreeCertificateChain(certChain);
CertFreeCertificateContext(cert);
- if(!trustError.empty())
- {
- throw trustError;
- }
}
- catch(const string& reason)
+
+ if(!trustError.empty())
{
if(_engine->getVerifyPeer() == 0)
{
if(_instance->traceLevel() >= 1)
{
_instance->logger()->trace(_instance->traceCategory(),
- "IceSSL: ignoring certificate verification failure:\n" + reason);
+ "IceSSL: ignoring certificate verification failure:\n" + trustError);
}
}
else
{
- ostringstream os;
- os << "IceSSL: certificate verification failure:\n" << reason;
- string msg = os.str();
+ string msg = "IceSSL: certificate verification failure:\n" + trustError;
if(_instance->traceLevel() >= 1)
{
_instance->logger()->trace(_instance->traceCategory(), msg);
diff --git a/cpp/src/IceSSL/SSLEngine.cpp b/cpp/src/IceSSL/SSLEngine.cpp
index bca84dfb066..607970b094e 100644
--- a/cpp/src/IceSSL/SSLEngine.cpp
+++ b/cpp/src/IceSSL/SSLEngine.cpp
@@ -128,9 +128,8 @@ IceSSL::SSLEngine::initialize()
if(_verifyPeer < 0 || _verifyPeer > 2)
{
- PluginInitializationException ex(__FILE__, __LINE__);
- ex.reason = "IceSSL: invalid value for " + propPrefix + "VerifyPeer";
- throw ex;
+ throw PluginInitializationException(__FILE__, __LINE__, "IceSSL: invalid value for " + propPrefix +
+ "VerifyPeer");
}
_securityTraceLevel = properties->getPropertyAsInt("IceSSL.Trace.Security");
@@ -218,9 +217,7 @@ IceSSL::SSLEngine::verifyPeerCertName(const string& address, const ConnectionInf
if(_verifyPeer > 0)
{
- SecurityException ex(__FILE__, __LINE__);
- ex.reason = msg;
- throw ex;
+ throw SecurityException(__FILE__, __LINE__, msg);
}
}
}
@@ -241,9 +238,7 @@ IceSSL::SSLEngine::verifyPeer(const string& address, const ConnectionInfoPtr& in
{
_logger->trace(_securityTraceCategory, msg + "\n" + desc);
}
- SecurityException ex(__FILE__, __LINE__);
- ex.reason = msg;
- throw ex;
+ throw SecurityException(__FILE__, __LINE__, msg);
}
if(!_trustManager->verify(info, desc))
@@ -253,9 +248,7 @@ IceSSL::SSLEngine::verifyPeer(const string& address, const ConnectionInfoPtr& in
{
_logger->trace(_securityTraceCategory, msg + "\n" + desc);
}
- SecurityException ex(__FILE__, __LINE__);
- ex.reason = msg;
- throw ex;
+ throw SecurityException(__FILE__, __LINE__, msg);
}
if(verifier && !verifier->verify(info))
@@ -265,9 +258,7 @@ IceSSL::SSLEngine::verifyPeer(const string& address, const ConnectionInfoPtr& in
{
_logger->trace(_securityTraceCategory, msg + "\n" + desc);
}
- SecurityException ex(__FILE__, __LINE__);
- ex.reason = msg;
- throw ex;
+ throw SecurityException(__FILE__, __LINE__, msg);
}
}
diff --git a/cpp/src/IceSSL/SecureTransportUtil.cpp b/cpp/src/IceSSL/SecureTransportUtil.cpp
index 23e501852ae..04de1c1a1ba 100644
--- a/cpp/src/IceSSL/SecureTransportUtil.cpp
+++ b/cpp/src/IceSSL/SecureTransportUtil.cpp
@@ -473,9 +473,8 @@ loadCerts(const string& file)
endpos = strbuf.find("-----END CERTIFICATE-----", startpos);
if(endpos == string::npos)
{
- InitializationException ex(__FILE__, __LINE__);
- ex.reason = "IceSSL: certificate " + file + " is not a valid PEM-encoded certificate";
- throw ex;
+ throw InitializationException(__FILE__, __LINE__, "IceSSL: certificate " + file +
+ " is not a valid PEM-encoded certificate");
}
size = endpos - startpos;
}
@@ -495,9 +494,8 @@ loadCerts(const string& file)
UniqueRef<SecCertificateRef> cert(SecCertificateCreateWithData(0, certdata.get()));
if(!cert)
{
- InitializationException ex(__FILE__, __LINE__);
- ex.reason = "IceSSL: certificate " + file + " is not a valid PEM-encoded certificate";
- throw ex;
+ throw InitializationException(__FILE__, __LINE__, "IceSSL: certificate " + file +
+ " is not a valid PEM-encoded certificate");
}
CFArrayAppendValue(const_cast<CFMutableArrayRef>(certs.get()), cert.get());
first = false;
@@ -509,9 +507,8 @@ loadCerts(const string& file)
UniqueRef<SecCertificateRef> cert(SecCertificateCreateWithData(0, data.get()));
if(!cert)
{
- InitializationException ex(__FILE__, __LINE__);
- ex.reason = "IceSSL: certificate " + file + " is not a valid DER-encoded certificate";
- throw ex;
+ throw InitializationException(__FILE__, __LINE__, "IceSSL: certificate " + file +
+ " is not a valid DER-encoded certificate");
}
CFArrayAppendValue(const_cast<CFMutableArrayRef>(certs.get()), cert.get());
}
diff --git a/cpp/src/IceSSL/TrustManager.cpp b/cpp/src/IceSSL/TrustManager.cpp
index 82b3f15ee2c..cd31365a427 100644
--- a/cpp/src/IceSSL/TrustManager.cpp
+++ b/cpp/src/IceSSL/TrustManager.cpp
@@ -54,11 +54,10 @@ TrustManager::TrustManager(const Ice::CommunicatorPtr& communicator) :
}
}
}
- catch(const ParseException& e)
+ catch(const ParseException& ex)
{
- Ice::PluginInitializationException ex(__FILE__, __LINE__);
- ex.reason = "IceSSL: invalid property " + key + ":\n" + e.reason;
- throw ex;
+ throw Ice::PluginInitializationException(__FILE__, __LINE__, "IceSSL: invalid property " + key + ":\n" +
+ ex.reason);
}
}
diff --git a/cpp/src/IceStorm/Service.cpp b/cpp/src/IceStorm/Service.cpp
index 5844e9853f8..3ae1fd891b0 100644
--- a/cpp/src/IceStorm/Service.cpp
+++ b/cpp/src/IceStorm/Service.cpp
@@ -172,10 +172,7 @@ ServiceI::start(
LoggerOutputBase s;
s << "exception while starting IceStorm service " << name << ":\n";
s << ex;
-
- IceBox::FailureException e(__FILE__, __LINE__);
- e.reason = s.str();
- throw e;
+ throw IceBox::FailureException(__FILE__, __LINE__, s.str());
}
topicAdapter->activate();
publishAdapter->activate();
@@ -201,9 +198,7 @@ ServiceI::start(
s << "exception while starting IceStorm service " << name << ":\n";
s << ex;
- IceBox::FailureException e(__FILE__, __LINE__);
- e.reason = s.str();
- throw e;
+ throw IceBox::FailureException(__FILE__, __LINE__, s.str());
}
}
else
@@ -396,9 +391,7 @@ ServiceI::start(
s << "exception while starting IceStorm service " << name << ":\n";
s << ex;
- IceBox::FailureException e(__FILE__, __LINE__);
- e.reason = s.str();
- throw e;
+ throw IceBox::FailureException(__FILE__, __LINE__, s.str());
}
}
@@ -440,9 +433,7 @@ ServiceI::start(const CommunicatorPtr& communicator,
s << "exception while starting IceStorm service " << name << ":\n";
s << ex;
- IceBox::FailureException e(__FILE__, __LINE__);
- e.reason = s.str();
- throw e;
+ throw IceBox::FailureException(__FILE__, __LINE__, s.str());
}
}
diff --git a/cpp/src/IceStorm/TopicI.cpp b/cpp/src/IceStorm/TopicI.cpp
index a9549467bc0..330354e43e5 100644
--- a/cpp/src/IceStorm/TopicI.cpp
+++ b/cpp/src/IceStorm/TopicI.cpp
@@ -652,9 +652,7 @@ TopicImpl::link(const TopicPrx& topic, Ice::Int cost)
if(p != _subscribers.end())
{
string name = IceStormInternal::identityToTopicName(id);
- LinkExists ex;
- ex.name = name;
- throw ex;
+ throw LinkExists(name);
}
LogUpdate llu;
@@ -708,9 +706,7 @@ TopicImpl::unlink(const TopicPrx& topic)
out << _name << ": unlink " << name << " failed - not linked";
}
- NoSuchLink ex;
- ex.name = name;
- throw ex;
+ throw NoSuchLink(name);
}
TraceLevelsPtr traceLevels = _instance->traceLevels();
diff --git a/cpp/src/IceStorm/TopicManagerI.cpp b/cpp/src/IceStorm/TopicManagerI.cpp
index db815c72654..8f0ddd0c6df 100644
--- a/cpp/src/IceStorm/TopicManagerI.cpp
+++ b/cpp/src/IceStorm/TopicManagerI.cpp
@@ -316,9 +316,7 @@ TopicManagerImpl::create(const string& name)
reap();
if(_topics.find(name) != _topics.end())
{
- TopicExists ex;
- ex.name = name;
- throw ex;
+ throw TopicExists(name);
}
// Identity is <instanceName>/topic.<topicname>
@@ -362,9 +360,7 @@ TopicManagerImpl::retrieve(const string& name) const
map<string, TopicImplPtr>::const_iterator p = _topics.find(name);
if(p == _topics.end())
{
- NoSuchTopic ex;
- ex.name = name;
- throw ex;
+ throw NoSuchTopic(name);
}
return p->second->proxy();
diff --git a/cpp/src/IceStorm/TransientTopicI.cpp b/cpp/src/IceStorm/TransientTopicI.cpp
index 1de6f0f7c70..a057330a676 100644
--- a/cpp/src/IceStorm/TransientTopicI.cpp
+++ b/cpp/src/IceStorm/TransientTopicI.cpp
@@ -393,10 +393,7 @@ TransientTopicImpl::link(const TopicPrx& topic, Ice::Int cost, const Ice::Curren
vector<SubscriberPtr>::iterator p = find(_subscribers.begin(), _subscribers.end(), record.id);
if(p != _subscribers.end())
{
- string name = IceStormInternal::identityToTopicName(id);
- LinkExists ex;
- ex.name = name;
- throw ex;
+ throw LinkExists(IceStormInternal::identityToTopicName(id));
}
SubscriberPtr subscriber = Subscriber::create(_instance, record);
@@ -424,10 +421,7 @@ TransientTopicImpl::unlink(const TopicPrx& topic, const Ice::Current&)
Ice::Trace out(traceLevels->logger, traceLevels->topicCat);
out << _name << ": unlink " << name << " failed - not linked";
}
-
- NoSuchLink ex;
- ex.name = name;
- throw ex;
+ throw NoSuchLink(name);
}
TraceLevelsPtr traceLevels = _instance->traceLevels();
diff --git a/cpp/src/IceStorm/TransientTopicManagerI.cpp b/cpp/src/IceStorm/TransientTopicManagerI.cpp
index b47ab853a04..b5beb39833b 100644
--- a/cpp/src/IceStorm/TransientTopicManagerI.cpp
+++ b/cpp/src/IceStorm/TransientTopicManagerI.cpp
@@ -40,9 +40,7 @@ TransientTopicManagerImpl::create(const string& name, const Ice::Current&)
if(_topics.find(name) != _topics.end())
{
- TopicExists ex;
- ex.name = name;
- throw ex;
+ throw TopicExists(name);
}
Ice::Identity id = IceStormInternal::nameToIdentity(_instance, name);
@@ -82,9 +80,7 @@ TransientTopicManagerImpl::retrieve(const string& name, const Ice::Current&) con
map<string, TransientTopicImplPtr>::const_iterator p = _topics.find(name);
if(p == _topics.end())
{
- NoSuchTopic ex;
- ex.name = name;
- throw ex;
+ throw NoSuchTopic(name);
}
// Here we cannot just reconstruct the identity since the
diff --git a/cpp/src/IceUtil/FileUtil.cpp b/cpp/src/IceUtil/FileUtil.cpp
index b006013ca97..e6a6a9284b2 100644
--- a/cpp/src/IceUtil/FileUtil.cpp
+++ b/cpp/src/IceUtil/FileUtil.cpp
@@ -454,9 +454,9 @@ IceUtilInternal::FileLock::FileLock(const std::string& path) :
//
if(::fcntl(_fd, F_SETLK, &lock) == -1)
{
- IceUtil::FileLockException ex(__FILE__, __LINE__, errno, _path);
+ int err = errno;
close(_fd);
- throw ex;
+ throw IceUtil::FileLockException(__FILE__, __LINE__, err, _path);
}
//
@@ -473,9 +473,9 @@ IceUtilInternal::FileLock::FileLock(const std::string& path) :
if(write(_fd, os.str().c_str(), os.str().size()) == -1)
{
- IceUtil::FileLockException ex(__FILE__, __LINE__, errno, _path);
+ int err = errno;
close(_fd);
- throw ex;
+ throw IceUtil::FileLockException(__FILE__, __LINE__, err, _path);
}
}
diff --git a/cpp/src/IceUtil/UUID.cpp b/cpp/src/IceUtil/UUID.cpp
index 3db155164d9..7b65508894a 100644
--- a/cpp/src/IceUtil/UUID.cpp
+++ b/cpp/src/IceUtil/UUID.cpp
@@ -98,7 +98,7 @@ IceUtil::generateUUID()
RPC_STATUS ret = UuidCreate(&uuid);
if(ret != RPC_S_OK && ret != RPC_S_UUID_LOCAL_ONLY && ret != RPC_S_UUID_NO_ADDRESS)
{
- throw new SyscallException(__FILE__, __LINE__, GetLastError());
+ throw SyscallException(__FILE__, __LINE__, GetLastError());
}
unsigned char* str;
@@ -106,7 +106,7 @@ IceUtil::generateUUID()
ret = UuidToString(&uuid, &str);
if(ret != RPC_S_OK)
{
- throw new SyscallException(__FILE__, __LINE__, GetLastError());
+ throw SyscallException(__FILE__, __LINE__, GetLastError());
}
string result = reinterpret_cast<char*>(str);
diff --git a/cpp/src/Slice/Python.cpp b/cpp/src/Slice/Python.cpp
index 4a46afd9fdb..b42fed00c7c 100644
--- a/cpp/src/Slice/Python.cpp
+++ b/cpp/src/Slice/Python.cpp
@@ -356,9 +356,7 @@ PackageVisitor::readInit(const string& dir, StringList& modules, StringList& sub
if(s.size() < 8)
{
- ostringstream os;
- os << "invalid line '" << s << "' in '" << initPath << "'";
- throw os.str();
+ throw runtime_error("invalid line '" + s + "' in '" + initPath + "'");
}
string name = s.substr(7);
@@ -388,16 +386,12 @@ PackageVisitor::readInit(const string& dir, StringList& modules, StringList& sub
{
if(state != InSubmodules)
{
- ostringstream os;
- os << "invalid line '" << s << "' in '" << initPath << "'";
- throw os.str();
+ throw runtime_error("invalid line '" + s + "' in '" + initPath + "'");
}
if(s.size() < 15)
{
- ostringstream os;
- os << "invalid line '" << s << "' in '" << initPath << "'";
- throw os.str();
+ throw runtime_error("invalid line '" + s + "' in '" + initPath + "'");
}
submodules.push_back(s.substr(14));
@@ -406,9 +400,7 @@ PackageVisitor::readInit(const string& dir, StringList& modules, StringList& sub
if(state == InModules)
{
- ostringstream os;
- os << "invalid format in '" << initPath << "'" << endl;
- throw os.str();
+ throw runtime_error("invalid format in '" + initPath + "'\n");
}
}
}
@@ -807,10 +799,10 @@ Slice::Python::compile(const vector<string>& argv)
consoleErr << argv[0] << ": error: " << ex.reason() << endl;
return EXIT_FAILURE;
}
- catch(const string& err)
+ catch(const exception& ex)
{
FileTracker::instance()->cleanup();
- consoleErr << argv[0] << ": error: " << err << endl;
+ consoleErr << argv[0] << ": error: " << ex.what() << endl;
status = EXIT_FAILURE;
}
}
diff --git a/cpp/src/iceserviceinstall/Install.cpp b/cpp/src/iceserviceinstall/Install.cpp
index 427d7533e98..05c97c10063 100644
--- a/cpp/src/iceserviceinstall/Install.cpp
+++ b/cpp/src/iceserviceinstall/Install.cpp
@@ -145,14 +145,9 @@ Install::run(int argc, char* argv[])
installer.install(properties);
}
}
- catch(const string& msg)
+ catch(const exception& ex)
{
- consoleErr << "Error: " << msg << endl;
- return EXIT_FAILURE;
- }
- catch(const Ice::Exception& ex)
- {
- consoleErr << "Error: " << ex << endl;
+ consoleErr << "Error: " << ex.what() << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
diff --git a/cpp/src/iceserviceinstall/ServiceInstaller.cpp b/cpp/src/iceserviceinstall/ServiceInstaller.cpp
index f5637c03b4e..5033fa5ed82 100644
--- a/cpp/src/iceserviceinstall/ServiceInstaller.cpp
+++ b/cpp/src/iceserviceinstall/ServiceInstaller.cpp
@@ -73,12 +73,12 @@ IceServiceInstaller::IceServiceInstaller(int serviceType, const string& configFi
{
if(_icegridInstanceName == "")
{
- throw "Ice.Default.Locator must be set in " + _configFile;
+ throw logic_error("Ice.Default.Locator must be set in " + _configFile);
}
_nodeName = _serviceProperties->getProperty("IceGrid.Node.Name");
if(_nodeName == "")
{
- throw "IceGrid.Node.Name must be set in " + _configFile;
+ throw logic_error("IceGrid.Node.Name must be set in " + _configFile);
}
_serviceName = serviceTypeToLowerString(_serviceType) + "." + _icegridInstanceName + "." + _nodeName;
}
@@ -89,7 +89,7 @@ IceServiceInstaller::IceServiceInstaller(int serviceType, const string& configFi
}
else
{
- throw "Unknown service type";
+ throw invalid_argument("Unknown service type");
}
}
}
@@ -117,24 +117,13 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
string displayName = properties->getPropertyWithDefault("DisplayName", defaultDisplayName[_serviceType]);
string description = properties->getPropertyWithDefault("Description", defaultDescription[_serviceType]);
- string imagePath = properties->getProperty("ImagePath");
- if(imagePath == "")
+ string imagePath = fixDirSeparator(properties->getPropertyWithDefault("ImagePath",
+ getServiceInstallerPath() + '\\' +
+ serviceTypeToLowerString(_serviceType) +
+ ".exe"));
+ if(!IceUtilInternal::fileExists(imagePath))
{
- string serviceInstallerPath = getServiceInstallerPath();
- if(serviceInstallerPath.empty())
- {
- throw "Can't get full path to service installer!";
- }
-
- imagePath = serviceInstallerPath + '\\' + serviceTypeToLowerString(_serviceType) + ".exe";
- }
- else
- {
- imagePath = fixDirSeparator(imagePath);
- }
- if(!fileExists(imagePath))
- {
- throw imagePath + ": not found";
+ throw runtime_error(imagePath + ": not found");
}
string dependency;
@@ -143,17 +132,18 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
{
if(properties->getPropertyAsInt("DependOnRegistry") != 0)
{
- throw "The IceGrid registry service can't depend on itself";
+ throw logic_error("The IceGrid registry service can't depend on itself");
}
string registryDataDir = fixDirSeparator(_serviceProperties->getProperty("IceGrid.Registry.LMDB.Path"));
if(registryDataDir == "")
{
- throw "IceGrid.Registry.LMDB.Path must be set in " + _configFile;
+ throw logic_error("IceGrid.Registry.LMDB.Path must be set in " + _configFile);
}
if(!IceUtilInternal::isAbsolutePath(registryDataDir))
{
- throw "'" + registryDataDir + "' is a relative path; IceGrid.Registry.LMDB.Path must be an absolute path";
+ throw logic_error("'" + registryDataDir +
+ "' is a relative path; IceGrid.Registry.LMDB.Path must be an absolute path");
}
if(!mkdir(registryDataDir))
@@ -166,11 +156,11 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
string nodeDataDir = fixDirSeparator(_serviceProperties->getProperty("IceGrid.Node.Data"));
if(nodeDataDir == "")
{
- throw "IceGrid.Node.Data must be set in " + _configFile;
+ throw logic_error("IceGrid.Node.Data must be set in " + _configFile);
}
if(!IceUtilInternal::isAbsolutePath(nodeDataDir))
{
- throw "'" + nodeDataDir + "' is a relative path; IceGrid.Node.Data must be an absolute path";
+ throw logic_error("'" + nodeDataDir + "' is a relative path; IceGrid.Node.Data must be an absolute path");
}
if(!mkdir(nodeDataDir))
@@ -191,7 +181,7 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
{
if(_icegridInstanceName == "")
{
- throw "Ice.Default.Locator must be set in " + _configFile + " when DependOnRegistry is not zero";
+ throw logic_error("Ice.Default.Locator must be set in " + _configFile + " when DependOnRegistry is not zero");
}
dependency = "icegridregistry." + _icegridInstanceName;
}
@@ -220,7 +210,7 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
if(scm == 0)
{
DWORD res = GetLastError();
- throw "Cannot open SCM: " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Cannot open SCM: " + IceUtilInternal::errorToString(res));
}
string deps = dependency;
@@ -253,7 +243,7 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
char fullPath[MAX_PATH];
if(GetFullPathName(_configFile.c_str(), MAX_PATH, fullPath, 0) > MAX_PATH)
{
- throw "Could not compute the full path of " + _configFile;
+ throw runtime_error("Could not compute the full path of " + _configFile);
}
command += string(fullPath) + "\"";
}
@@ -288,7 +278,7 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
{
DWORD res = GetLastError();
CloseServiceHandle(scm);
- throw "Cannot create service" + _serviceName + ": " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Cannot create service" + _serviceName + ": " + IceUtilInternal::errorToString(res));
}
//
@@ -302,7 +292,7 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
DWORD res = GetLastError();
CloseServiceHandle(scm);
CloseServiceHandle(service);
- throw "Cannot set description for service" + _serviceName + ": " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Cannot set description for service" + _serviceName + ": " + IceUtilInternal::errorToString(res));
}
CloseServiceHandle(scm);
@@ -316,7 +306,7 @@ IceServiceInstaller::uninstall()
if(scm == 0)
{
DWORD res = GetLastError();
- throw "Cannot open SCM: " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Cannot open SCM: " + IceUtilInternal::errorToString(res));
}
//
@@ -328,7 +318,7 @@ IceServiceInstaller::uninstall()
{
DWORD res = GetLastError();
CloseServiceHandle(scm);
- throw "Cannot open service '" + _serviceName + "': " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Cannot open service '" + _serviceName + "': " + IceUtilInternal::errorToString(res));
}
//
@@ -342,7 +332,7 @@ IceServiceInstaller::uninstall()
{
CloseServiceHandle(scm);
CloseServiceHandle(service);
- throw "Cannot stop service '" + _serviceName + "': " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Cannot stop service '" + _serviceName + "': " + IceUtilInternal::errorToString(res));
}
}
@@ -351,7 +341,7 @@ IceServiceInstaller::uninstall()
DWORD res = GetLastError();
CloseServiceHandle(scm);
CloseServiceHandle(service);
- throw "Cannot delete service '" + _serviceName + "': " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Cannot delete service '" + _serviceName + "': " + IceUtilInternal::errorToString(res));
}
CloseServiceHandle(scm);
@@ -366,7 +356,7 @@ IceServiceInstaller::uninstall()
}
}
-/*static*/ vector<string>
+vector<string>
IceServiceInstaller::getPropertyNames()
{
static const string propertyNames[] = { "ImagePath", "DisplayName", "ObjectName", "Password",
@@ -377,7 +367,7 @@ IceServiceInstaller::getPropertyNames()
return result;
}
-/*static*/ string
+string
IceServiceInstaller::serviceTypeToString(int serviceType)
{
static const string serviceTypeArray[] = { "IceGridRegistry", "IceGridNode", "Glacier2Router" };
@@ -392,7 +382,7 @@ IceServiceInstaller::serviceTypeToString(int serviceType)
}
}
-/*static*/ string
+string
IceServiceInstaller::serviceTypeToLowerString(int serviceType)
{
static const string serviceTypeArray[] = { "icegridregistry", "icegridnode", "glacier2router" };
@@ -407,27 +397,18 @@ IceServiceInstaller::serviceTypeToLowerString(int serviceType)
}
}
-/*static*/ string
+string
IceServiceInstaller::getServiceInstallerPath()
{
- string path;
-
- char buffer[MAX_PATH];
- DWORD size = GetModuleFileName(0, buffer, MAX_PATH);
- if(size > 0)
+ wchar_t buffer[MAX_PATH];
+ if(!GetModuleFileNameW(0, buffer, MAX_PATH))
{
- path = string(buffer, size);
- size_t p = path.find_last_of("/\\");
- if(p != string::npos)
- {
- path = path.substr(0, p);
- }
- else
- {
- path = "";
- }
+ throw runtime_error("Can not get full path to service installer:\n" + IceUtilInternal::lastErrorToString());
}
- return path;
+
+ string path = wstringToString(buffer);
+ assert(path.find_last_of("/\\"));
+ return path.substr(0, path.find_last_of("/\\"));
}
void
@@ -457,7 +438,8 @@ IceServiceInstaller::initializeSid(const string& name)
domainName.resize(domainNameSize);
continue;
}
- throw "Could not retrieve Security ID for " + name + ": " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not retrieve Security ID for " + name + ": " +
+ IceUtilInternal::errorToString(res));
}
_sid = reinterpret_cast<SID*>(_sidBuffer.data());
}
@@ -488,7 +470,8 @@ IceServiceInstaller::initializeSid(const string& name)
if(LookupAccountSidW(0, _sid, accountName, &accountNameLen, domainName, &domainLen, &nameUse) == false)
{
DWORD res = GetLastError();
- throw "Could not retrieve full account name for " + name + ": " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not retrieve full account name for " + name + ": " +
+ IceUtilInternal::errorToString(res));
}
_sidName = wstringToString(domainName) + "\\" + wstringToString(accountName);
@@ -505,35 +488,6 @@ IceServiceInstaller::initializeSid(const string& name)
}
}
-bool
-IceServiceInstaller::fileExists(const string& path) const
-{
- IceUtilInternal::structstat st = {0};
- int err = IceUtilInternal::stat(path, &st);
-
- if(err == 0)
- {
- if((S_ISREG(st.st_mode)) == 0)
- {
- throw path + " is not a regular file";
- }
- return true;
- }
- else
- {
- if(errno == ENOENT)
- {
- return false;
- }
- else
- {
- char msg[128];
- strerror_s(msg, 128, errno);
- throw "Problem with " + path + ": " + msg;
- }
- }
-}
-
void
IceServiceInstaller::grantPermissions(const string& path, SE_OBJECT_TYPE type, bool inherit, bool fullControl) const
{
@@ -559,7 +513,7 @@ IceServiceInstaller::grantPermissions(const string& path, SE_OBJECT_TYPE type, b
flags, 0, 0, &acl, 0, &sd);
if(res != ERROR_SUCCESS)
{
- throw "Could not retrieve securify info for " + path + ": " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not retrieve securify info for " + path + ": " + IceUtilInternal::errorToString(res));
}
//
@@ -569,14 +523,14 @@ IceServiceInstaller::grantPermissions(const string& path, SE_OBJECT_TYPE type, b
{
if(!AuthzInitializeResourceManager(AUTHZ_RM_FLAG_NO_AUDIT, 0, 0, 0, 0, &manager))
{
- throw "AutzInitializeResourceManager failed: " + IceUtilInternal::lastErrorToString();
+ throw runtime_error("AutzInitializeResourceManager failed: " + IceUtilInternal::lastErrorToString());
}
LUID unusedId = { 0 };
if(!AuthzInitializeContextFromSid(0, _sid, manager, 0, unusedId, 0, &clientContext))
{
- throw "AuthzInitializeContextFromSid failed: " + IceUtilInternal::lastErrorToString();
+ throw runtime_error("AuthzInitializeContextFromSid failed: " + IceUtilInternal::lastErrorToString());
}
AUTHZ_ACCESS_REQUEST accessRequest = { 0 };
@@ -597,7 +551,7 @@ IceServiceInstaller::grantPermissions(const string& path, SE_OBJECT_TYPE type, b
if(!AuthzAccessCheck(0, clientContext, &accessRequest, 0, sd, 0, 0, &accessReply, 0))
{
- throw "AuthzAccessCheck failed: " + IceUtilInternal::lastErrorToString();
+ throw runtime_error("AuthzAccessCheck failed: " + IceUtilInternal::lastErrorToString());
}
bool done = false;
@@ -658,15 +612,15 @@ IceServiceInstaller::grantPermissions(const string& path, SE_OBJECT_TYPE type, b
res = SetEntriesInAclW(1, &ea, acl, &newAcl);
if(res != ERROR_SUCCESS)
{
- throw "Could not modify ACL for " + path + ": " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not modify ACL for " + path + ": " + IceUtilInternal::errorToString(res));
}
res = SetNamedSecurityInfoW(const_cast<wchar_t*>(stringToWstring(path).c_str()), type,
DACL_SECURITY_INFORMATION, 0, 0, newAcl, 0);
if(res != ERROR_SUCCESS)
{
- throw "Could not grant access to " + _sidName + " on " + path + ": " +
- IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not grant access to " + _sidName + " on " + path + ": " +
+ IceUtilInternal::errorToString(res));
}
if(_debug)
@@ -714,7 +668,7 @@ IceServiceInstaller::mkdir(const string& path) const
}
else
{
- throw "Could not create directory " + path + ": " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not create directory " + path + ": " + IceUtilInternal::errorToString(res));
}
}
else
@@ -742,13 +696,13 @@ IceServiceInstaller::addLog(const string& log) const
if(res != ERROR_SUCCESS)
{
- throw "Could not create new Event Log '" + log + "': " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not create new Event Log '" + log + "': " + IceUtilInternal::errorToString(res));
}
res = RegCloseKey(key);
if(res != ERROR_SUCCESS)
{
- throw "Could not close registry key handle: " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not close registry key handle: " + IceUtilInternal::errorToString(res));
}
}
@@ -766,7 +720,7 @@ IceServiceInstaller::removeLog(const string& log) const
//
if(res != ERROR_SUCCESS && res != ERROR_ACCESS_DENIED)
{
- throw "Could not remove registry key '" + createLog(log) + "': " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not remove registry key '" + createLog(log) + "': " + IceUtilInternal::errorToString(res));
}
}
@@ -783,7 +737,7 @@ IceServiceInstaller::addSource(const string& source, const string& log, const st
0, L"REG_SZ", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &key, &disposition);
if(res != ERROR_SUCCESS)
{
- throw "Could not create Event Log source in registry: " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not create Event Log source in registry: " + IceUtilInternal::errorToString(res));
}
//
@@ -809,13 +763,13 @@ IceServiceInstaller::addSource(const string& source, const string& log, const st
if(res != ERROR_SUCCESS)
{
RegCloseKey(key);
- throw "Could not set registry key: " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not set registry key: " + IceUtilInternal::errorToString(res));
}
res = RegCloseKey(key);
if(res != ERROR_SUCCESS)
{
- throw "Could not close registry key handle: " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not close registry key handle: " + IceUtilInternal::errorToString(res));
}
}
@@ -833,7 +787,7 @@ IceServiceInstaller::removeSource(const string& source) const
if(res != ERROR_SUCCESS)
{
- throw "Could not open EventLog key: " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not open EventLog key: " + IceUtilInternal::errorToString(res));
}
DWORD index = 0;
@@ -860,7 +814,7 @@ IceServiceInstaller::removeSource(const string& source) const
res = RegCloseKey(key);
if(res != ERROR_SUCCESS)
{
- throw "Could not close registry key handle: " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not close registry key handle: " + IceUtilInternal::errorToString(res));
}
return wstringToString(subkey);
}
@@ -872,18 +826,18 @@ IceServiceInstaller::removeSource(const string& source) const
if(res == ERROR_NO_MORE_ITEMS)
{
RegCloseKey(key);
- throw "Could not locate EventLog with source '" + source + "'";
+ throw runtime_error("Could not locate EventLog with source '" + source + "'");
}
else
{
RegCloseKey(key);
- throw "Error while searching EventLog with source '" + source + "': " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Error while searching EventLog with source '" + source + "': " + IceUtilInternal::errorToString(res));
}
res = RegCloseKey(key);
if(res != ERROR_SUCCESS)
{
- throw "Could not close registry key handle: " + IceUtilInternal::errorToString(res);
+ throw runtime_error("Could not close registry key handle: " + IceUtilInternal::errorToString(res));
}
return ""; // To keep compilers happy.
@@ -945,24 +899,16 @@ IceServiceInstaller::getIceDLLPath(const string& imagePath) const
os << 'a' << (patchVersion - 50);
}
- string version = os.str();
+ const string version = os.str();
string result = imagePathDir + '\\' + "ice" + version + ".dll";
-
- if(fileExists(result))
- {
- return result;
- }
- else
+ if(!IceUtilInternal::fileExists(result))
{
result = imagePathDir + '\\' + "ice" + version + "d.dll";
- if(fileExists(result))
+ if(!IceUtilInternal::fileExists(result))
{
- return result;
- }
- else
- {
- throw "Could not find Ice DLL";
+ throw runtime_error("Could not find Ice DLL");
}
}
+ return result;
}
diff --git a/cpp/src/slice2html/Gen.cpp b/cpp/src/slice2html/Gen.cpp
index 50a6f18553b..58b28ef2799 100644
--- a/cpp/src/slice2html/Gen.cpp
+++ b/cpp/src/slice2html/Gen.cpp
@@ -1685,8 +1685,7 @@ Slice::GeneratorBase::readFile(const string& file, string& part1, string& part2)
if(!foundTitle)
{
- string err = "no TITLE marker in `" + file + "'";
- throw err;
+ throw logic_error("no TITLE marker in `" + file + "'");
}
ostringstream p2;
diff --git a/cpp/test/IceSSL/configuration/AllTests.cpp b/cpp/test/IceSSL/configuration/AllTests.cpp
index 6c9d80feb4c..7eaefdff373 100644
--- a/cpp/test/IceSSL/configuration/AllTests.cpp
+++ b/cpp/test/IceSSL/configuration/AllTests.cpp
@@ -85,7 +85,7 @@ readFile(const string& file, vector<char>& buffer)
ifstream is(file.c_str(), ios::in | ios::binary);
if(!is.good())
{
- throw "error opening file " + file;
+ throw runtime_error("error opening file " + file);
}
is.seekg(0, is.end);
@@ -96,7 +96,7 @@ readFile(const string& file, vector<char>& buffer)
if(!is.good())
{
- throw "error reading file " + file;
+ throw runtime_error("error reading file " + file);
}
}