Skip to content

Commit

Permalink
C++ catch exception cleanup (#1947)
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone authored Mar 16, 2024
1 parent d78794c commit 7ebe256
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 63 deletions.
10 changes: 0 additions & 10 deletions cpp/src/Ice/PluginManagerI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,6 @@ Ice::PluginManagerI::destroy() noexcept
Warning out(getProcessLogger());
out << "unexpected exception raised by plug-in `" << p->name << "' destruction:\n" << ex.what();
}
catch (const std::string& str)
{
Warning out(getProcessLogger());
out << "unexpected exception raised by plug-in `" << p->name << "' destruction:\n" << str;
}
catch (const char* msg)
{
Warning out(getProcessLogger());
out << "unexpected exception raised by plug-in `" << p->name << "' destruction:\n" << msg;
}
catch (...)
{
Warning out(getProcessLogger());
Expand Down
16 changes: 0 additions & 16 deletions cpp/src/Ice/Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,22 +806,6 @@ Ice::Service::run(int argc, const char* const argv[], const InitializationData&
#ifdef ICE_USE_SYSTEMD
const string msg = err.str();
sd_notifyf(0, "STATUS=Failed service terminating after catching exception: %s", msg.c_str());
#endif
}
catch (const std::string& msg)
{
ServiceError err(this);
err << "service terminating after catching exception:\n" << msg;
#ifdef ICE_USE_SYSTEMD
sd_notifyf(0, "STATUS=Failed service terminating after catching exception: %s", msg.c_str());
#endif
}
catch (const char* msg)
{
ServiceError err(this);
err << "service terminating after catching exception:\n" << msg;
#ifdef ICE_USE_SYSTEMD
sd_notifyf(0, "STATUS=Failed service terminating after catching exception: %s", msg);
#endif
}
catch (...)
Expand Down
53 changes: 19 additions & 34 deletions cpp/src/IceGrid/RegistryI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,26 @@ RegistryI::startImpl()
_wellKnownObjects->addEndpoint("Server", _serverAdapter->createDirectProxy(dummy));
_wellKnownObjects->addEndpoint("Internal", _registryAdapter->createDirectProxy(dummy));

if (!setupUserAccountMapper())
//
// Setup file user account mapper object if the property is set.
//
string userAccountFileProperty = properties->getProperty("IceGrid.Registry.UserAccounts");
if (!userAccountFileProperty.empty())
{
return false;
try
{
Identity mapperId{
_master ? "RegistryUserAccountMapper" : "RegistryUserAccountMapper-" + _replicaName,
_instanceName};
_registryAdapter->add(make_shared<FileUserAccountMapperI>(userAccountFileProperty), mapperId);
_wellKnownObjects->add(_registryAdapter->createProxy(mapperId), string{UserAccountMapper::ice_staticId()});
}
catch (const Ice::Exception& ex)
{
Error out(_communicator->getLogger());
out << "unable to setup file user account mapper:\n" << ex;
return false;
}
}

setupLocatorRegistry();
Expand Down Expand Up @@ -716,38 +733,6 @@ RegistryI::setupInternalRegistry()
return registry;
}

bool
RegistryI::setupUserAccountMapper()
{
auto properties = _communicator->getProperties();

//
// Setup file user account mapper object if the property is set.
//
string userAccountFileProperty = properties->getProperty("IceGrid.Registry.UserAccounts");
if (!userAccountFileProperty.empty())
{
try
{
Identity mapperId{"RegistryUserAccountMapper", _instanceName};
if (!_master)
{
mapperId.name += "-" + _replicaName;
}

_registryAdapter->add(make_shared<FileUserAccountMapperI>(userAccountFileProperty), mapperId);
_wellKnownObjects->add(_registryAdapter->createProxy(mapperId), string{UserAccountMapper::ice_staticId()});
}
catch (const string& msg)
{
Error out(_communicator->getLogger());
out << msg;
return false;
}
}
return true;
}

shared_ptr<ObjectAdapter>
RegistryI::setupClientSessionFactory(const IceGrid::LocatorPrx& locator)
{
Expand Down
1 change: 0 additions & 1 deletion cpp/src/IceGrid/RegistryI.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ namespace IceGrid
QueryPrx setupQuery();
RegistryPrx setupRegistry();
InternalRegistryPrx setupInternalRegistry();
bool setupUserAccountMapper();
std::shared_ptr<Ice::ObjectAdapter> setupClientSessionFactory(const LocatorPrx&);
std::shared_ptr<Ice::ObjectAdapter> setupAdminSessionFactory(
const std::shared_ptr<Ice::Object>&,
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/slice2php/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,10 +1598,10 @@ 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;
}
}
Expand Down

0 comments on commit 7ebe256

Please sign in to comment.