mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Shared/Utilities: Handle string format exceptions
Handle StringFormat() exceptions in case of malformed string format to avoid causing unhandled exception crashes
(cherry picked from commit c79811de4f)
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user