Shared/Utilities: Handle string format exceptions

Handle StringFormat() exceptions in case of malformed string format to avoid causing unhandled exception crashes
This commit is contained in:
Giacomo Pozzoni authored and Ovahlord committed 2025-07-21 09:14:46 +02:00
1 parent 5410539f05
commit a576c8328b
1 file changed
+9 -1
+9 -1
View File
@@ -26,7 +26,15 @@ namespace Trinity
template<typename Format, typename... Args>
inline std::string StringFormat(Format&& fmt, Args&&... args)
{
return fmt::sprintf(std::forward<Format>(fmt), std::forward<Args>(args)...);
try
{
return fmt::sprintf(std::forward<Format>(fmt), std::forward<Args>(args)...);
}
catch (const fmt::FormatError& formatError)
{
std::string error = "An error occurred formatting string \"" + std::string(fmt) + "\" : " + std::string(formatError.what());
return error;
}
}
/// Returns true if the given char pointer is null.