add formatChecked(), which does not crash on bad format strings
[folly.git] / folly / FormatArg.h
index 4099c13005f2227a78bb425ca140e7a0c150ac29..48bfe2af8bb2061312b4fc488e4ef289e5b9c943 100644 (file)
 
 namespace folly {
 
+class BadFormatArg : public std::invalid_argument {
+ public:
+  explicit BadFormatArg(const std::string& msg)
+    : std::invalid_argument(msg) {}
+};
+
 /**
  * Parsed format argument.
  */
@@ -197,7 +203,7 @@ inline std::string FormatArg::errorStr(Args&&... args) const {
 
 template <typename... Args>
 inline void FormatArg::error(Args&&... args) const {
-  throw std::invalid_argument(errorStr(std::forward<Args>(args)...));
+  throw BadFormatArg(errorStr(std::forward<Args>(args)...));
 }
 
 template <bool emptyOk>