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
2019-02-15 08:52:43 +01:00
committed by jackpoz
parent 58c5dfac1d
commit c79811de4f

View File

@@ -27,7 +27,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.