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:
1 parent
5410539f05
commit
a576c8328b
1 file changed
+9
-1
@@ -26,7 +26,15 @@ namespace Trinity
|
|||||||
template<typename Format, typename... Args>
|
template<typename Format, typename... Args>
|
||||||
inline std::string StringFormat(Format&& fmt, Args&&... 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.
|
/// Returns true if the given char pointer is null.
|
||||||
|
|||||||
Reference in new issue
Block a user