diff options
author | Giacomo Pozzoni <giacomopoz@gmail.com> | 2019-02-15 08:52:43 +0100 |
---|---|---|
committer | jackpoz <giacomopoz@gmail.com> | 2019-02-15 20:01:10 +0100 |
commit | c79811de4fbf2b22cd74f55853516c7fc307055f (patch) | |
tree | cce34d543fd897525e81489672e3424469d87524 /src | |
parent | 58c5dfac1d8d314b9243fde52466b3c933fb7d7f (diff) |
Shared/Utilities: Handle string format exceptions
Handle StringFormat() exceptions in case of malformed string format to avoid causing unhandled exception crashes
Diffstat (limited to 'src')
-rw-r--r-- | src/common/Utilities/StringFormat.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/common/Utilities/StringFormat.h b/src/common/Utilities/StringFormat.h index b14fb2beb34..680f6eefc55 100644 --- a/src/common/Utilities/StringFormat.h +++ b/src/common/Utilities/StringFormat.h @@ -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. |