diff --git a/src/utils/general.hpp b/src/utils/general.hpp index 2a7ef82147d..90ece712f46 100644 --- a/src/utils/general.hpp +++ b/src/utils/general.hpp @@ -17,6 +17,11 @@ #include #include #include +#include + +#if defined(__clang__) || defined(__GNUG__) +#include +#endif namespace utils { @@ -85,4 +90,31 @@ inline bool contains(const Container& container, const Value& value) return detail::contains_impl::eval(container, value); } +/** + * For the GCC/clang compilers, return the unmangled name of an unknown exception that was caught. + * Meaning something caught with `catch(...)`. + * + * @return std::string + */ +inline std::string get_unknown_exception_type() +{ +#if defined(__clang__) || defined(__GNUG__) + std::string to_demangle = __cxxabiv1::__cxa_current_exception_type()->name(); + int status = 0; + char* buff = __cxxabiv1::__cxa_demangle(to_demangle.c_str(), NULL, NULL, &status); + if(status == 0) + { + std::string demangled = buff; + std::free(buff); + return demangled; + } + else + { + return to_demangle; + } +#else + return ""; +#endif +} + } // namespace utils