From 9178ba706f528a48555540e1d70115338418d14b Mon Sep 17 00:00:00 2001 From: Trevor Hollmann <thollmann@uni-koblenz.de> Date: Tue, 22 Jun 2021 08:27:51 +0200 Subject: [PATCH] [#79] Refactor function for recursive exception printing. The name "print_what" is not self-explanatory... --- .../src/vkcv/asset/asset_loader.cpp | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp index 1c0ac5d2..b5a10920 100644 --- a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp +++ b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp @@ -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("/"); -- GitLab