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

Use throw_exception in Optional

Summary: [Folly] Use `throw_exception` in `Optional`, which also respects all stated reasons why the `throw` statement is moved to a separate `.cpp` - to outline it and to permit replacement of its implementation with a call to `std::terminate`.

Reviewed By: akrieger

Differential Revision: D7728129

fbshipit-source-id: 0539f9d16a719b52f5a81b13b5d2ce2b61d36de0
parent 9f646cf0
/*
* Copyright 2017-present 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/Optional.h>
namespace folly {
namespace detail {
void throw_optional_empty_exception() {
throw OptionalEmptyException();
}
} // namespace detail
} // namespace folly
......@@ -63,6 +63,7 @@
#include <folly/Portability.h>
#include <folly/Traits.h>
#include <folly/Utility.h>
#include <folly/lang/Exception.h>
namespace folly {
......@@ -72,11 +73,6 @@ class Optional;
namespace detail {
struct NoneHelper {};
// Allow each translation unit to control its own -fexceptions setting.
// If exceptions are disabled, std::terminate() will be called instead of
// throwing OptionalEmptyException when the condition fails.
[[noreturn]] void throw_optional_empty_exception();
template <class Value>
struct OptionalPromiseReturn;
} // namespace detail
......@@ -321,7 +317,7 @@ class Optional {
private:
void require_value() const {
if (!storage_.hasValue) {
detail::throw_optional_empty_exception();
throw_exception<OptionalEmptyException>();
}
}
......
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