Skip to content
Snippets Groups Projects
Commit 9178ba70 authored by Trevor Hollmann's avatar Trevor Hollmann
Browse files

[#79] Refactor function for recursive exception printing.

The name "print_what" is not self-explanatory...
parent d9b6b748
No related branches found
No related tags found
1 merge request!69Resolve "Rework Asset Loader API"
Pipeline #25925 failed
......@@ -13,6 +13,21 @@
namespace vkcv::asset {
/**
* This function unrolls nested exceptions via recursion and prints them
* @param e error code
* @param path path to file that is responsible for error
*/
void recurseExceptionPrint(const std::exception& e, const std::string &path)
{
vkcv_log(LogLevel::ERROR, "Loading file %s: %s", path.c_str(), e.what());
try {
std::rethrow_if_nested(e);
} catch (const std::exception& nested) {
recurseExceptionPrint(nested, path);
}
}
/**
* Computes the component count for an accessor type of the fx-gltf library.
* @param type The accessor type
......@@ -34,22 +49,6 @@ uint8_t getCompCount(const fx::gltf::Accessor::Type type) {
}
}
/**
* This function unrolls nested exceptions via recursion and prints them
* @param e error code
* @param path path to file that is responsible for error
*/
void print_what (const std::exception& e, const std::string &path) {
vkcv_log(LogLevel::ERROR, "Loading file %s: %s",
path.c_str(), e.what());
try {
std::rethrow_if_nested(e);
} catch (const std::exception& nested) {
print_what(nested, path);
}
}
/**
* Translate the component type used in the index accessor of fx-gltf to our
* enum for index type. The reason we have defined an incompatible enum that
......@@ -194,10 +193,10 @@ int loadScene(const std::string &path, Scene &scene){
sceneObjects = fx::gltf::LoadFromText(path);
}
} catch (const std::system_error &err) {
print_what(err, path);
recurseExceptionPrint(err, path);
return ASSET_ERROR;
} catch (const std::exception &e) {
print_what(e, path);
recurseExceptionPrint(e, path);
return ASSET_ERROR;
}
size_t pos = path.find_last_of("/");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment