2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include <folly/ExceptionWrapper.h>
20 #include <folly/Logging.h>
24 exception_wrapper::VTable const exception_wrapper::uninit_{
25 &noop_<void, exception_wrapper const*, exception_wrapper*>,
26 &noop_<void, exception_wrapper*, exception_wrapper*>,
27 &noop_<void, exception_wrapper*>,
28 &noop_<void, exception_wrapper const*>,
30 &noop_<std::exception const*, exception_wrapper const*>,
31 &noop_<exception_wrapper, exception_wrapper const*>};
33 exception_wrapper::VTable const exception_wrapper::ExceptionPtr::ops_{
42 exception_wrapper::VTable const exception_wrapper::SharedPtr::ops_{
52 std::exception const* get_std_exception_(std::exception_ptr eptr) noexcept {
54 std::rethrow_exception(eptr);
55 } catch (const std::exception& ex) {
63 exception_wrapper::exception_wrapper(std::exception_ptr ptr) noexcept
64 : exception_wrapper{} {
66 if (auto e = get_std_exception_(ptr)) {
68 << "Performance error: Please construct exception_wrapper with a "
69 "reference to the std::exception along with the "
70 "std::exception_ptr.";
71 *this = exception_wrapper{std::move(ptr), *e};
74 *this = exception_wrapper{ptr, uk};
79 [[noreturn]] void exception_wrapper::onNoExceptionError() {
80 std::ios_base::Init ioinit_; // ensure std::cerr is alive
82 << "Cannot use `throw_exception` with an empty folly::exception_wrapper"
87 fbstring exceptionStr(exception_wrapper const& ew) {