properly handle unexpected exceptions
Prior code followed a poorly explained example and then would
just re-throw the exception without actually catching it. The
new code (while specific to gcc and clang) will log the unexpected
exception type so it will not be fatal.
Tested: throw an std::string in a handler and see that it is not fatal.
MESSAGE=Handler failed to catch exception
EXCEPTION=std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >
Change-Id: I4734aba8ea6fb02ad8ce54be55e860d2b4c6576c
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/ipmid-new.cpp b/ipmid-new.cpp
index 88a51b5..be809cf 100644
--- a/ipmid-new.cpp
+++ b/ipmid-new.cpp
@@ -606,17 +606,10 @@
}
catch (...)
{
- std::exception_ptr eptr = std::current_exception();
- try
- {
- std::rethrow_exception(eptr);
- }
- catch (std::exception& e)
- {
- log<level::ERR>("ERROR opening IPMI provider",
- entry("PROVIDER=%s", name.c_str()),
- entry("ERROR=%s", e.what()));
- }
+ const char* what = currentExceptionType();
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "ERROR opening IPMI provider",
+ entry("PROVIDER=%s", name.c_str()), entry("ERROR=%s", what));
}
if (!isOpen())
{