RMG-Core: use std::runtime_error instead of std::terminate in Directories.cpp

This commit is contained in:
Rosalie Wanders committed 2025-03-17 00:15:10 +01:00
1 parent 64d4c41d1d
commit 9bc56e90ee
1 file changed
+4 -6
+4 -6
View File
@@ -17,7 +17,7 @@
#include "m64p/Api.hpp"
#include <filesystem>
#include <iostream>
#include <stdexcept>
#include <optional>
#include <cstdlib>
#include <cstdio>
@@ -58,15 +58,14 @@ static std::filesystem::path get_exe_directory(void)
if (GetModuleFileNameW(nullptr, buffer, MAX_PATH) == 0)
{
MessageBoxA(nullptr, "get_exe_directory: GetModuleFileNameW() Failed!", "Error", MB_OK | MB_ICONERROR);
std::terminate();
throw std::runtime_error("get_exe_directory: GetModuleFileNameW() failed");
}
directory = std::filesystem::path(buffer).parent_path();
#else // _WIN32
directory = std::filesystem::canonical("/proc/self/exe", errorCode).parent_path();
if (errorCode)
{
std::cerr << "get_exe_directory: std::filesystem::canonical(\"/proc/self/exe\") failed: " << errorCode.message() << std::endl;
std::terminate();
throw std::runtime_error("get_exe_directory: std::filesystem::canonical(\"/proc/self/exe\") failed: " + errorCode.message());
}
#endif // _WIN32
return directory.make_preferred();
@@ -112,8 +111,7 @@ static std::filesystem::path get_var_directory(std::string var, std::string appe
env = std::getenv(fallbackVar.c_str());
if (env == nullptr)
{
std::cerr << "get_var_directory: fallbackVar: $" << fallbackVar << " cannot be nullptr!" << std::endl;
std::terminate();
throw std::runtime_error("get_var_directory: fallbackVar: $" + fallbackVar + " cannot be non-existent");
}
directory = env;
directory += fallbackAppend;