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

Use throw_exception in Try

Summary: [Folly] Use `throw_exception` in `Try`, replacing the one-off throwing functions.

Reviewed By: Orvid

Differential Revision: D7984674

fbshipit-source-id: 3996e09fd8a7446fbb53760f1ce30a66cb7c13e9
parent c1a2ae85
......@@ -661,7 +661,6 @@ libfolly_la_SOURCES = \
system/ThreadName.cpp \
Subprocess.cpp \
TimeoutQueue.cpp \
Try.cpp \
Uri.cpp \
experimental/ThreadedRepeatingFunctionRunner.cpp \
experimental/bser/Dump.cpp \
......
......@@ -131,7 +131,7 @@ void Try<T>::throwIfFailed() const {
case Contains::EXCEPTION:
e_.throw_exception();
default:
try_detail::throwUsingUninitializedTry();
throw_exception<UsingUninitializedTry>();
}
}
......
/*
* 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/Try.h>
namespace folly {
namespace try_detail {
[[noreturn]] void throwTryDoesNotContainException() {
throw TryException("exception(): Try does not contain an exception");
}
[[noreturn]] void throwUsingUninitializedTry() {
throw UsingUninitializedTry();
}
} // namespace try_detail
} // namespace folly
......@@ -22,6 +22,7 @@
#include <folly/Unit.h>
#include <folly/Utility.h>
#include <folly/functional/Invoke.h>
#include <folly/lang/Exception.h>
#include <exception>
#include <stdexcept>
#include <type_traits>
......@@ -39,11 +40,6 @@ class FOLLY_EXPORT UsingUninitializedTry : public TryException {
UsingUninitializedTry() : TryException("Using uninitialized try") {}
};
namespace try_detail {
[[noreturn]] void throwTryDoesNotContainException();
[[noreturn]] void throwUsingUninitializedTry();
} // namespace try_detail
/*
* Try<T> is a wrapper that contains either an instance of T, an exception, or
* nothing. Exceptions are stored as exception_wrappers so that the user can
......@@ -232,28 +228,28 @@ class Try {
exception_wrapper& exception() & {
if (!hasException()) {
try_detail::throwTryDoesNotContainException();
throw_exception<TryException>("Try does not contain an exception");
}
return e_;
}
exception_wrapper&& exception() && {
if (!hasException()) {
try_detail::throwTryDoesNotContainException();
throw_exception<TryException>("Try does not contain an exception");
}
return std::move(e_);
}
const exception_wrapper& exception() const & {
if (!hasException()) {
try_detail::throwTryDoesNotContainException();
throw_exception<TryException>("Try does not contain an exception");
}
return e_;
}
const exception_wrapper&& exception() const && {
if (!hasException()) {
try_detail::throwTryDoesNotContainException();
throw_exception<TryException>("Try does not contain an exception");
}
return std::move(e_);
}
......@@ -415,28 +411,28 @@ class Try<void> {
*/
exception_wrapper& exception() & {
if (!hasException()) {
try_detail::throwTryDoesNotContainException();
throw_exception<TryException>("Try does not contain an exception");
}
return e_;
}
exception_wrapper&& exception() && {
if (!hasException()) {
try_detail::throwTryDoesNotContainException();
throw_exception<TryException>("Try does not contain an exception");
}
return std::move(e_);
}
const exception_wrapper& exception() const & {
if (!hasException()) {
try_detail::throwTryDoesNotContainException();
throw_exception<TryException>("Try does not contain an exception");
}
return e_;
}
const exception_wrapper&& exception() const && {
if (!hasException()) {
try_detail::throwTryDoesNotContainException();
throw_exception<TryException>("Try does not contain an exception");
}
return std::move(e_);
}
......
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