35 lines
979 B
C++
35 lines
979 B
C++
#include <mix_cc/exception/exception.h>
|
|
#include <mix_cc/exception/get_nested_exception.h>
|
|
#include <iostream>
|
|
namespace mix_cc {
|
|
std::string get_nested_exception(const std::exception& e, int level) {
|
|
std::string str;
|
|
if (level == 0) {
|
|
str.push_back('{');
|
|
}
|
|
std::string tmp = e.what();
|
|
if (tmp.empty()) {
|
|
str += "\"level_" + std::to_string(level) +
|
|
"\":{\"null exception, fatal error\"},";
|
|
} else if (tmp.front() == '\"') {
|
|
str += "\"level_" + std::to_string(level) + "\":" + e.what() + ",";
|
|
} else {
|
|
str += "\"level_" + std::to_string(level) + "\":\"" + e.what() + "\",";
|
|
}
|
|
try {
|
|
std::rethrow_if_nested(e);
|
|
} catch (const std::exception& e) {
|
|
str += get_nested_exception(e, level + 1);
|
|
}
|
|
if (level == 0) {
|
|
str.pop_back();
|
|
str.push_back('}');
|
|
}
|
|
return str;
|
|
}
|
|
|
|
json get_nested_exception_json(const std::exception& e, int level) {
|
|
return json::parse(get_nested_exception(e, level));
|
|
}
|
|
} // namespace mix_cc
|