| 80 | } |
| 81 | |
| 82 | std::pair<std::string, std::optional<PM_STATUS>> ReportException(std::string note, std::exception_ptr pEx) noexcept |
| 83 | { |
| 84 | if (!pEx) { |
| 85 | pEx = std::current_exception(); |
| 86 | } |
| 87 | const auto concat = [&](std::string what) { |
| 88 | if (!note.empty()) { |
| 89 | return note + "\n" + what; |
| 90 | } |
| 91 | else { |
| 92 | return what; |
| 93 | } |
| 94 | }; |
| 95 | if (pEx) { |
| 96 | try { |
| 97 | std::rethrow_exception(pEx); |
| 98 | } |
| 99 | catch (const pmon::util::Exception& e) { |
| 100 | try { |
| 101 | if (e.HasPmStatus()) { |
| 102 | return { concat(std::format("[{}] {}", typeid(e).name(), e.what())), e.GeneratePmStatus() }; |
| 103 | } |
| 104 | else { |
| 105 | return { concat(std::format("[{}] {}", typeid(e).name(), e.what())), std::nullopt }; |
| 106 | } |
| 107 | } |
| 108 | catch (...) { return {}; } |
| 109 | } |
| 110 | catch (const std::exception& e) { |
| 111 | try { return { concat(std::format("[{}] {}", typeid(e).name(), e.what())), std::nullopt }; } |
| 112 | catch (...) { return {}; } |
| 113 | } |
| 114 | catch (...) { |
| 115 | return { concat("Unrecognized exception"), std::nullopt }; |
| 116 | } |
| 117 | } |
| 118 | return { concat("No exception in flight"), std::nullopt }; |
| 119 | } |
| 120 | |
| 121 | PM_STATUS GeneratePmStatus(std::exception_ptr pEx) noexcept |
| 122 | { |