To avoid std::terminate() in case of exception in destructor, this patch
adds exception handlers. Now instead of terminating application, an
error will be printed.
Change-Id: Ia5db61559b649df8eb1803ef730c518e96e9f283
ProxyImpl(Eldbus_Proxy *Value, bool EraseOnExit = false) : Value(Value), EraseOnExit(EraseOnExit) {}
~ProxyImpl()
{
- for (auto &it : destructors)
- if (it)
- it();
+ try {
+ for (auto &it : destructors)
+ if (it)
+ it();
+ } catch (...) {
+ DBUS_DEBUG("ProxyImpl: Exception in destructor");
+ }
}
};
DEFINE_GS(Proxy, Eldbus_Proxy, )
OwnerNameCallbackHandle::~OwnerNameCallbackHandle()
{
- if (callback_)
- callback_();
+ try {
+ if (callback_) {
+ callback_();
+ }
+ } catch (...) {
+ DBUS_DEBUG("Exception in OwnerNameCallbackHandle destructor");
+ }
}
OwnerNameCallbackHandle DBus::registerNameOwnerChangedCallback(DBusWrapper::ConnectionPtr connection, const std::string &bus, std::function<void(std::string, std::string)> fnc_)
}
const char *what() const noexcept override
{
- text = temp->str();
+ try {
+ text = temp->str();
+ } catch (...) {
+ return "Exception information is not available due to memory allocation issue";
+ }
return text.c_str();
}
};
std::vector<std::function<void()>> destructors;
~DestructorObject()
{
- for (auto &a : destructors)
- a();
+ try {
+ for (auto &a : destructors)
+ a();
+ } catch (...) {
+ DBUS_DEBUG("Fatal issue: unhandled exception in destructor");
+ }
}
};
std::unique_ptr<DestructorObject> destructorObject{new DestructorObject()};