Commit 2562ef37 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Outline throw statements in format

Summary: [Folly] Outline `throw` statements in `format`.

Reviewed By: Orvid

Differential Revision: D5523933

fbshipit-source-id: 371c9ecc707e48dcc05fa4aab4fd326111466161
parent a961f2cd
......@@ -180,7 +180,7 @@ void BaseFormatter<Derived, containerMode, Args...>::operator()(
p = q;
if (p == end || *p != '}') {
throw BadFormatArg("folly::format: single '}' in format string");
throwBadFormatArg("folly::format: single '}' in format string");
}
++p;
}
......@@ -202,7 +202,7 @@ void BaseFormatter<Derived, containerMode, Args...>::operator()(
p = q + 1;
if (p == end) {
throw BadFormatArg("folly::format: '}' at end of format string");
throwBadFormatArg("folly::format: '}' at end of format string");
}
// "{{" -> "{"
......@@ -215,7 +215,7 @@ void BaseFormatter<Derived, containerMode, Args...>::operator()(
// Format string
q = static_cast<const char*>(memchr(p, '}', size_t(end - p)));
if (q == nullptr) {
throw BadFormatArg("folly::format: missing ending '}'");
throwBadFormatArg("folly::format: missing ending '}'");
}
FormatArg arg(StringPiece(p, q));
p = q + 1;
......@@ -264,7 +264,7 @@ void BaseFormatter<Derived, containerMode, Args...>::operator()(
}
if (hasDefaultArgIndex && hasExplicitArgIndex) {
throw BadFormatArg(
throwBadFormatArg(
"folly::format: may not have both default and explicit arg indexes");
}
......@@ -290,10 +290,10 @@ namespace format_value {
template <class FormatCallback>
void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb) {
if (arg.width != FormatArg::kDefaultWidth && arg.width < 0) {
throw BadFormatArg("folly::format: invalid width");
throwBadFormatArg("folly::format: invalid width");
}
if (arg.precision != FormatArg::kDefaultPrecision && arg.precision < 0) {
throw BadFormatArg("folly::format: invalid precision");
throwBadFormatArg("folly::format: invalid precision");
}
if (arg.precision != FormatArg::kDefaultPrecision &&
......
/*
* Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/FormatArg.h>
namespace folly {
[[noreturn]] void throwBadFormatArg(char const* msg) {
throw BadFormatArg(msg);
}
[[noreturn]] void throwBadFormatArg(std::string const& msg) {
throw BadFormatArg(msg);
}
}
......@@ -26,11 +26,12 @@
namespace folly {
class BadFormatArg : public std::invalid_argument {
public:
explicit BadFormatArg(const std::string& msg)
: std::invalid_argument(msg) {}
using invalid_argument::invalid_argument;
};
[[noreturn]] void throwBadFormatArg(char const* msg);
[[noreturn]] void throwBadFormatArg(std::string const& msg);
/**
* Parsed format argument.
*/
......@@ -213,7 +214,7 @@ inline std::string FormatArg::errorStr(Args&&... args) const {
template <typename... Args>
[[noreturn]] inline void FormatArg::error(Args&&... args) const {
throw BadFormatArg(errorStr(std::forward<Args>(args)...));
throwBadFormatArg(errorStr(std::forward<Args>(args)...));
}
template <bool emptyOk>
......
......@@ -454,6 +454,7 @@ libfollybase_la_SOURCES = \
detail/RangeCommon.cpp \
EscapeTables.cpp \
Format.cpp \
FormatArg.cpp \
FormatTables.cpp \
MallctlHelper.cpp \
portability/BitsFunctexcept.cpp \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment